From 543e0d9c896d323f0d4e3f35cbb394d806f5692b Mon Sep 17 00:00:00 2001 From: Dainius S Date: Tue, 18 Aug 2020 12:44:26 +0300 Subject: [PATCH 1/9] Drop support for VCD 9.5 --- CHANGELOG.md | 1 + govcd/api_vcd.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc890abc4..e5e340de2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ [#326](https://github.com/vmware/go-vcloud-director/pull/326) * Update VDC dynamic func to handle API version 35.0 [#327](https://github.com/vmware/go-vcloud-director/pull/327) * Added methods `vm.UpdateVmCpuAndMemoryHotAdd` and `vm.UpdateVmCpuAndMemoryHotAddAsyc` [#324](https://github.com/vmware/go-vcloud-director/pull/324) +* Drop support for VMware Cloud Director 9.5 [#330](https://github.com/vmware/go-vcloud-director/pull/330) ## 2.8.0 (June 30, 2020) diff --git a/govcd/api_vcd.go b/govcd/api_vcd.go index 83addcd4a..dade6bfe5 100644 --- a/govcd/api_vcd.go +++ b/govcd/api_vcd.go @@ -89,7 +89,7 @@ func NewVCDClient(vcdEndpoint url.URL, insecure bool, options ...VCDClientOption // Setting defaults vcdClient := &VCDClient{ Client: Client{ - APIVersion: "31.0", // supported by 9.5, 9.7, 10.0, 10.1 + APIVersion: "32.0", // supported by 9.7+ VCDHREF: vcdEndpoint, Http: http.Client{ Transport: &http.Transport{ From 7623fcea60894691bb368f8f1670affadbdba8c8 Mon Sep 17 00:00:00 2001 From: Dainius S Date: Tue, 18 Aug 2020 13:45:26 +0300 Subject: [PATCH 2/9] Remove code for handling API versions pre 32.0 --- govcd/adminorg.go | 5 +-- govcd/adminvdc.go | 94 ++++-------------------------------------- govcd/adminvdc_test.go | 10 ----- govcd/vapp.go | 4 +- govcd/vm.go | 13 +++--- 5 files changed, 18 insertions(+), 108 deletions(-) diff --git a/govcd/adminorg.go b/govcd/adminorg.go index 99ecb47aa..3c7a19e2d 100644 --- a/govcd/adminorg.go +++ b/govcd/adminorg.go @@ -581,9 +581,8 @@ func (adminOrg *AdminOrg) GetVDCByHref(vdcHref string) (*Vdc, error) { vdc := NewVdc(adminOrg.client) - _, err := adminOrg.client.ExecuteRequestWithApiVersion(vdcHREF, http.MethodGet, - "", "error getting vdc: %s", nil, vdc.Vdc, - adminOrg.client.GetSpecificApiVersionOnCondition(">= 32.0", "32.0")) + _, err := adminOrg.client.ExecuteRequest(vdcHREF, http.MethodGet, + "", "error getting vdc: %s", nil, vdc.Vdc) if err != nil { return nil, err diff --git a/govcd/adminvdc.go b/govcd/adminvdc.go index 58bb57c81..43a8478ec 100644 --- a/govcd/adminvdc.go +++ b/govcd/adminvdc.go @@ -34,15 +34,6 @@ type vdcVersionedFuncs struct { UpdateVdcAsync func(adminVdc *AdminVdc) (Task, error) } -// VDC function mapping for API version 31.0 (from vCD 9.5) -var vdcVersionedFuncsV95 = vdcVersionedFuncs{ - SupportedVersion: "31.0", - CreateVdc: createVdc, - CreateVdcAsync: createVdcAsync, - UpdateVdc: updateVdc, - UpdateVdcAsync: updateVdcAsync, -} - // VDC function mapping for API version 32.0 (from vCD 9.7) var vdcVersionedFuncsV97 = vdcVersionedFuncs{ SupportedVersion: "32.0", @@ -54,7 +45,6 @@ var vdcVersionedFuncsV97 = vdcVersionedFuncs{ // vdcVersionedFuncsByVcdVersion is a map of VDC functions by vCD version var vdcVersionedFuncsByVcdVersion = map[string]vdcVersionedFuncs{ - "vdc9.5": vdcVersionedFuncsV95, "vdc9.7": vdcVersionedFuncsV97, // If we add a new function to this list, we also need to update the "default" entry @@ -91,16 +81,9 @@ func (adminOrg *AdminOrg) GetAdminVdcByName(vdcname string) (AdminVdc, error) { // GetAdminVDCByHref retrieves a VDC using a direct call with the HREF func (adminOrg *AdminOrg) GetAdminVDCByHref(vdcHref string) (*AdminVdc, error) { - adminVdc := NewAdminVdc(adminOrg.client) - - // We are executing below request with a specific API version in the header, because we want to retrieve the most - // available fields in AdminVdc which vCD provides, but also which our code understands. As we can't blindly use - // the latest version, we're limiting the highest used version to the one we support with - // the GetSpecificApiVersionOnCondition(...) function. Specifically, the API version 32 returns - // two additional fields: IncludeMemoryOverhead and IsElastic for Flex allocation - _, err := adminOrg.client.ExecuteRequestWithApiVersion(vdcHref, http.MethodGet, - "", "error getting vdc: %s", nil, adminVdc.AdminVdc, adminVdc.client.GetSpecificApiVersionOnCondition(">= 32.0", "32.0")) + _, err := adminOrg.client.ExecuteRequest(vdcHref, http.MethodGet, + "", "error getting vdc: %s", nil, adminVdc.AdminVdc) if err != nil { return nil, err @@ -219,13 +202,8 @@ func (adminVdc *AdminVdc) Refresh() error { // elements in slices. unmarshalledAdminVdc := &types.AdminVdc{} - // We are executing below request with a specific API version in the header, because we want to retrieve the most - // available fields in AdminVdc which vCD provides, but also which our code understands. As we can't blindly use - // the latest version, we're limiting the highest used version to the one we support with - // the GetSpecificApiVersionOnCondition(...) function. Specifically, the API version 32 returns - // two additional fields: IncludeMemoryOverhead and IsElastic for Flex allocation - _, err := adminVdc.client.ExecuteRequestWithApiVersion(adminVdc.AdminVdc.HREF, http.MethodGet, - "", "error refreshing VDC: %s", nil, unmarshalledAdminVdc, adminVdc.client.GetSpecificApiVersionOnCondition(">= 32.0", "32.0")) + _, err := adminVdc.client.ExecuteRequest(adminVdc.AdminVdc.HREF, http.MethodGet, + "", "error refreshing VDC: %s", nil, unmarshalledAdminVdc) if err != nil { return err } @@ -311,53 +289,6 @@ func (adminOrg *AdminOrg) CreateOrgVdcAsync(vdcConfiguration *types.VdcConfigura return vdcFunctions.CreateVdcAsync(adminOrg, vdcConfiguration) } -// createVdc creates a VDC with the given params under the given organization. -// Returns a Vdc pointer and an error -func createVdc(adminOrg *AdminOrg, vdcConfiguration *types.VdcConfiguration) (*Vdc, error) { - util.Logger.Printf("[TRACE] createVdc called %#v", *vdcConfiguration) - err := adminOrg.CreateVdcWait(vdcConfiguration) - if err != nil { - return nil, err - } - - vdc, err := adminOrg.GetVDCByName(vdcConfiguration.Name, true) - if err != nil { - return nil, err - } - return vdc, nil -} - -// updateVdcAsync updates a VDC with the given params. Returns a Task and error -func updateVdcAsync(adminVdc *AdminVdc) (Task, error) { - util.Logger.Printf("[TRACE] updateVdcAsync called %#v", *adminVdc) - adminVdc.AdminVdc.Xmlns = types.XMLNamespaceVCloud - - // Return the task - return adminVdc.client.ExecuteTaskRequest(adminVdc.AdminVdc.HREF, http.MethodPut, - types.MimeAdminVDC, "error updating VDC: %s", adminVdc.AdminVdc) -} - -// updateVdc updates a VDC with the given params. Returns an AdminVdc. -func updateVdc(adminVdc *AdminVdc) (*AdminVdc, error) { - util.Logger.Printf("[TRACE] updateVdc called %#v", *adminVdc) - task, err := updateVdcAsync(adminVdc) - if err != nil { - return nil, err - } - - err = task.WaitTaskCompletion() - if err != nil { - return nil, err - } - - err = adminVdc.Refresh() - if err != nil { - return nil, err - } - - return adminVdc, nil -} - // updateVdcAsyncV97 updates a VDC with the given params. Supports Flex type allocation. // Needs vCD 9.7+ to work. Returns a Task and an error. func updateVdcAsyncV97(adminVdc *AdminVdc) (Task, error) { @@ -365,9 +296,8 @@ func updateVdcAsyncV97(adminVdc *AdminVdc) (Task, error) { adminVdc.AdminVdc.Xmlns = types.XMLNamespaceVCloud // Return the task - return adminVdc.client.ExecuteTaskRequestWithApiVersion(adminVdc.AdminVdc.HREF, http.MethodPut, - types.MimeAdminVDC, "error updating VDC: %s", adminVdc.AdminVdc, - adminVdc.client.GetSpecificApiVersionOnCondition(">= 32.0", "32.0")) + return adminVdc.client.ExecuteTaskRequest(adminVdc.AdminVdc.HREF, http.MethodPut, + types.MimeAdminVDC, "error updating VDC: %s", adminVdc.AdminVdc) } // updateVdcV97 updates a VDC with the given params @@ -390,13 +320,6 @@ func updateVdcV97(adminVdc *AdminVdc) (*AdminVdc, error) { return adminVdc, nil } -// createVdcAsync creates a VDC with the given params under the given organization. -// Returns a Task and an error -func createVdcAsync(adminOrg *AdminOrg, vdcConfiguration *types.VdcConfiguration) (Task, error) { - util.Logger.Printf("[TRACE] createVdcAsync called %#v", *vdcConfiguration) - return adminOrg.CreateVdc(vdcConfiguration) -} - // createVdcV97 creates a VDC with the given params under the given organization // and waits for the asynchronous task to complete. Supports Flex type allocation. // Needs vCD 9.7+ to work. Returns a Vdc pointer and error. @@ -437,10 +360,9 @@ func createVdcAsyncV97(adminOrg *AdminOrg, vdcConfiguration *types.VdcConfigurat adminVdc := NewAdminVdc(adminOrg.client) - _, err = adminOrg.client.ExecuteRequestWithApiVersion(vdcCreateHREF.String(), http.MethodPost, + _, err = adminOrg.client.ExecuteRequest(vdcCreateHREF.String(), http.MethodPost, "application/vnd.vmware.admin.createVdcParams+xml", "error creating VDC: %s", - vdcConfiguration, adminVdc.AdminVdc, - adminOrg.client.GetSpecificApiVersionOnCondition(">= 32.0", "32.0")) + vdcConfiguration, adminVdc.AdminVdc) if err != nil { return Task{}, err } diff --git a/govcd/adminvdc_test.go b/govcd/adminvdc_test.go index ff242597f..85ce09292 100644 --- a/govcd/adminvdc_test.go +++ b/govcd/adminvdc_test.go @@ -24,11 +24,6 @@ func (vcd *TestVCD) Test_CreateOrgVdcWithFlex(check *C) { check.Skip(fmt.Sprintf(TestRequiresSysAdminPrivileges, check.TestName())) } - // Flex vCD supported from 9.7 vCD - if vcd.client.Client.APIVCDMaxVersionIs("< 32.0") { - check.Skip(fmt.Sprintf("Test %s requires vCD 9.7 (API version 32) or higher", check.TestName())) - } - if vcd.config.VCD.ProviderVdc.Name == "" { check.Skip("No Provider VDC name given for VDC tests") } @@ -162,11 +157,6 @@ func (vcd *TestVCD) Test_UpdateVdcFlex(check *C) { check.Skip(fmt.Sprintf(TestRequiresSysAdminPrivileges, check.TestName())) } - // Flex vCD supported from 9.7 vCD - if vcd.client.Client.APIVCDMaxVersionIs("< 32.0") { - check.Skip(fmt.Sprintf("Test %s requires vCD 9.7 (API version 32) or higher", check.TestName())) - } - adminOrg, vdcConfiguration, err := setupVdc(vcd, check, "Flex") check.Assert(err, IsNil) diff --git a/govcd/vapp.go b/govcd/vapp.go index a6d65b620..15a275a34 100644 --- a/govcd/vapp.go +++ b/govcd/vapp.go @@ -1255,8 +1255,8 @@ func (client *Client) GetVMByHref(vmHref string) (*VM, error) { newVm := NewVM(client) - _, err := client.ExecuteRequestWithApiVersion(vmHref, http.MethodGet, - "", "error retrieving vm: %s", nil, newVm.VM, client.GetSpecificApiVersionOnCondition(">= 32.0", "32.0")) + _, err := client.ExecuteRequest(vmHref, http.MethodGet, + "", "error retrieving vm: %s", nil, newVm.VM) if err != nil { diff --git a/govcd/vm.go b/govcd/vm.go index 81c4eec79..fd9fb86cb 100644 --- a/govcd/vm.go +++ b/govcd/vm.go @@ -72,8 +72,8 @@ func (vm *VM) Refresh() error { // elements in slices. vm.VM = &types.VM{} - _, err := vm.client.ExecuteRequestWithApiVersion(refreshUrl, http.MethodGet, - "", "error refreshing VM: %s", nil, vm.VM, vm.client.GetSpecificApiVersionOnCondition(">= 32.0", "32.0")) + _, err := vm.client.ExecuteRequest(refreshUrl, http.MethodGet, + "", "error refreshing VM: %s", nil, vm.VM) // The request was successful return err @@ -1345,7 +1345,7 @@ func (vm *VM) UpdateInternalDisksAsync(disksSettingToUpdate *types.VmSpecSection vmSpecSectionModified := true disksSettingToUpdate.Modified = &vmSpecSectionModified - return vm.client.ExecuteTaskRequestWithApiVersion(vm.VM.HREF+"/action/reconfigureVm", http.MethodPost, + return vm.client.ExecuteTaskRequest(vm.VM.HREF+"/action/reconfigureVm", http.MethodPost, types.MimeVM, "error updating VM disks: %s", &types.VMDiskChange{ XMLName: xml.Name{}, Xmlns: types.XMLNamespaceVCloud, @@ -1353,8 +1353,7 @@ func (vm *VM) UpdateInternalDisksAsync(disksSettingToUpdate *types.VmSpecSection Name: vm.VM.Name, VmSpecSection: disksSettingToUpdate, // API version requirements changes through vCD version to access VmSpecSection - }, vm.client.GetSpecificApiVersionOnCondition(">= 32.0", "32.0")) - + }) } // AddEmptyVm adds an empty VM (without template) to vApp and returns the new created VM or an error. @@ -1465,7 +1464,7 @@ func (vm *VM) UpdateVmSpecSectionAsync(vmSettingsToUpdate *types.VmSpecSection, // GuestCustomizationSection // Sections not included in the request body will not be updated. - return vm.client.ExecuteTaskRequestWithApiVersion(vm.VM.HREF+"/action/reconfigureVm", http.MethodPost, + return vm.client.ExecuteTaskRequest(vm.VM.HREF+"/action/reconfigureVm", http.MethodPost, types.MimeVM, "error updating VM spec section: %s", &types.VM{ XMLName: xml.Name{}, Xmlns: types.XMLNamespaceVCloud, @@ -1474,7 +1473,7 @@ func (vm *VM) UpdateVmSpecSectionAsync(vmSettingsToUpdate *types.VmSpecSection, Description: description, VmSpecSection: vmSettingsToUpdate, // API version requirements changes through vCD version to access VmSpecSection - }, vm.client.GetSpecificApiVersionOnCondition(">= 32.0", "32.0")) + }) } // QueryVmList returns a list of all VMs in all the organizations available to the caller From 26f8deb18002f53e4cec406fd016c932e32f193b Mon Sep 17 00:00:00 2001 From: Dainius S Date: Tue, 18 Aug 2020 14:06:45 +0300 Subject: [PATCH 3/9] Remove unused comments --- govcd/vm.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/govcd/vm.go b/govcd/vm.go index fd9fb86cb..bc0eeeff4 100644 --- a/govcd/vm.go +++ b/govcd/vm.go @@ -1352,7 +1352,6 @@ func (vm *VM) UpdateInternalDisksAsync(disksSettingToUpdate *types.VmSpecSection Ovf: types.XMLNamespaceOVF, Name: vm.VM.Name, VmSpecSection: disksSettingToUpdate, - // API version requirements changes through vCD version to access VmSpecSection }) } @@ -1472,7 +1471,6 @@ func (vm *VM) UpdateVmSpecSectionAsync(vmSettingsToUpdate *types.VmSpecSection, Name: vm.VM.Name, Description: description, VmSpecSection: vmSettingsToUpdate, - // API version requirements changes through vCD version to access VmSpecSection }) } From f255574e0a99f505869ffad249ec3e7f72322f60 Mon Sep 17 00:00:00 2001 From: Dainius S Date: Tue, 18 Aug 2020 16:52:11 +0300 Subject: [PATCH 4/9] Fix unit test --- .../TestSamlAdfsAuthenticate_RESP_api_versions.golden | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test-resources/golden/TestSamlAdfsAuthenticate_RESP_api_versions.golden b/test-resources/golden/TestSamlAdfsAuthenticate_RESP_api_versions.golden index 3539e9ffb..ba80fb02a 100644 --- a/test-resources/golden/TestSamlAdfsAuthenticate_RESP_api_versions.golden +++ b/test-resources/golden/TestSamlAdfsAuthenticate_RESP_api_versions.golden @@ -48,6 +48,10 @@ 31.0 https://192.168.1.109/api/sessions + + 32.0 + https://192.168.1.109/api/sessions + 5.5 https://192.168.1.109/api/sessions @@ -1042,4 +1046,4 @@ http://192.168.1.109/api/v1.5/schema/vmwextensions.xsd - \ No newline at end of file + From 7e5e2e0e054d70defcef86c5a4932370894eb0dc Mon Sep 17 00:00:00 2001 From: Dainius S Date: Wed, 19 Aug 2020 12:01:29 +0300 Subject: [PATCH 5/9] checkOpenApiEndpointCompatibility() should return system default API version when it is higher --- govcd/openapi_endpoints.go | 7 +++++++ govcd/openapi_test.go | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/govcd/openapi_endpoints.go b/govcd/openapi_endpoints.go index c546fcac6..199141de0 100644 --- a/govcd/openapi_endpoints.go +++ b/govcd/openapi_endpoints.go @@ -6,6 +6,7 @@ package govcd import ( "fmt" + "github.com/vmware/go-vcloud-director/v2/types/v56" ) @@ -17,6 +18,7 @@ var endpointMinApiVersions = map[string]string{ // checkOpenApiEndpointCompatibility checks if VCD version (to which the client is connected) is sufficient to work with // specified OpenAPI endpoint and returns either error, either Api version to use for calling that endpoint. This Api // version can then be supplied to low level OpenAPI client functions. +// If the system default API version is higher than endpoint introduction version - default system one is used. func (client *Client) checkOpenApiEndpointCompatibility(endpoint string) (string, error) { minimumApiVersion, ok := endpointMinApiVersions[endpoint] if !ok { @@ -32,5 +34,10 @@ func (client *Client) checkOpenApiEndpointCompatibility(endpoint string) (string endpoint, minimumApiVersion, maxSupportedVersion) } + // If default API version is higher than minimum required API version for endpoint - use the system default one. + if client.APIClientVersionIs("> " + minimumApiVersion) { + return client.APIVersion, nil + } + return minimumApiVersion, nil } diff --git a/govcd/openapi_test.go b/govcd/openapi_test.go index cc845fca3..674d9e099 100644 --- a/govcd/openapi_test.go +++ b/govcd/openapi_test.go @@ -127,8 +127,9 @@ func (vcd *TestVCD) Test_OpenApiInlineStructAudiTrail(check *C) { // 8. Update role once more using "Sync" version of PUT function // 9. Delete role once again func (vcd *TestVCD) Test_OpenApiInlineStructCRUDRoles(check *C) { - minimumRequiredApiVersion := "31.0" endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointRoles + minimumRequiredApiVersion, err := vcd.client.Client.checkOpenApiEndpointCompatibility(endpoint) + check.Assert(err, IsNil) skipOpenApiEndpointTest(vcd, check, endpoint, minimumRequiredApiVersion) // Step 1 - Get all roles From 9fe929542c274b652f70aeebf836693bba37c856 Mon Sep 17 00:00:00 2001 From: Dainius S Date: Thu, 20 Aug 2020 12:01:40 +0300 Subject: [PATCH 6/9] Deprecated vdc.UploadMediaImage --- CHANGELOG.md | 1 + govcd/media.go | 4 +- govcd/media_test.go | 101 -------------------------------------------- 3 files changed, 4 insertions(+), 102 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85c31d13d..fc35466ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ `OpenApiDeleteItem`, `OpenApiIsSupported`, `OpenApiBuildEndpoints` [#325](https://github.com/vmware/go-vcloud-director/pull/325) * Drop support for VMware Cloud Director 9.5 [#330](https://github.com/vmware/go-vcloud-director/pull/330) +* Deprecate Vdc.UploadMediaImage because it no longer works with API V32.0+ [#330](https://github.com/vmware/go-vcloud-director/pull/330) ## 2.8.0 (June 30, 2020) diff --git a/govcd/media.go b/govcd/media.go index 44c1fee2c..549dbd089 100644 --- a/govcd/media.go +++ b/govcd/media.go @@ -61,7 +61,9 @@ func NewMediaRecord(cli *Client) *MediaRecord { // Uploads an ISO file as media. This method only uploads bits to vCD spool area. // Returns errors if any occur during upload from vCD or upload process. On upload fail client may need to // remove vCD catalog item which waits for files to be uploaded. -// Recommend to use catalog.UploadMediaImage which let's expect in which catalog file will be placed +// +// Deprecated: This method is broken in API V32.0+. Please use catalog.UploadMediaImage because VCD does not support +// uploading directly to VDC anymore. func (vdc *Vdc) UploadMediaImage(mediaName, mediaDescription, filePath string, uploadPieceSize int64) (UploadTask, error) { util.Logger.Printf("[TRACE] UploadImage: %s, image name: %v \n", mediaName, mediaDescription) diff --git a/govcd/media_test.go b/govcd/media_test.go index d50f67773..ecdd46ba5 100644 --- a/govcd/media_test.go +++ b/govcd/media_test.go @@ -8,111 +8,10 @@ package govcd import ( "fmt" - "io/ioutil" - "os" . "gopkg.in/check.v1" ) -// Tests System function UploadMediaImage by checking if provided standard iso file uploaded. -func (vcd *TestVCD) Test_UploadMediaImage(check *C) { - fmt.Printf("Running: %s\n", check.TestName()) - - skipWhenMediaPathMissing(vcd, check) - - uploadTask, err := vcd.vdc.UploadMediaImage(TestUploadMedia, "upload from test", vcd.config.Media.MediaPath, 1024) - check.Assert(err, IsNil) - err = uploadTask.WaitTaskCompletion() - check.Assert(err, IsNil) - - AddToCleanupList(TestUploadMedia, "mediaImage", vcd.org.Org.Name+"|"+vcd.vdc.Vdc.Name, "Test_UploadMediaImage") - - verifyMediaImageUploaded(vcd.vdc, check, TestUploadMedia) -} - -func verifyMediaImageUploaded(vdc *Vdc, check *C, itemName string) { - results, err := queryMediaWithFilter(vdc, "name=="+itemName) - - check.Assert(err, Equals, nil) - check.Assert(len(results), Equals, 1) -} - -// Tests System function UploadMediaImage by checking UploadTask.GetUploadProgress returns values of progress. -func (vcd *TestVCD) Test_UploadMediaImage_progress_works(check *C) { - fmt.Printf("Running: %s\n", check.TestName()) - - skipWhenMediaPathMissing(vcd, check) - itemName := TestUploadMedia + "2" - - uploadTask, err := vcd.vdc.UploadMediaImage(itemName, "upload from test", vcd.config.Media.MediaPath, 1024) - check.Assert(err, IsNil) - for { - if value := uploadTask.GetUploadProgress(); value == "100.00" { - break - } else { - check.Assert(value, Not(Equals), "") - } - } - err = uploadTask.WaitTaskCompletion() - check.Assert(err, IsNil) - - AddToCleanupList(itemName, "mediaImage", vcd.org.Org.Name+"|"+vcd.vdc.Vdc.Name, "Test_UploadMediaImage") - - verifyMediaImageUploaded(vcd.vdc, check, itemName) -} - -// Tests System function UploadMediaImage by checking UploadTask.ShowUploadProgress writes values of progress to stdin. -func (vcd *TestVCD) Test_UploadMediaImage_ShowUploadProgress_works(check *C) { - fmt.Printf("Running: %s\n", check.TestName()) - - skipWhenMediaPathMissing(vcd, check) - itemName := TestUploadMedia + "3" - - uploadTask, err := vcd.vdc.UploadMediaImage(itemName, "upload from test", vcd.config.Media.MediaPath, 1024) - check.Assert(err, IsNil) - - //take control of stdout - oldStdout := os.Stdout - r, w, _ := os.Pipe() - os.Stdout = w - - err = uploadTask.ShowUploadProgress() - check.Assert(err, IsNil) - - w.Close() - //read stdin - result, _ := ioutil.ReadAll(r) - os.Stdout = oldStdout - - err = uploadTask.WaitTaskCompletion() - check.Assert(err, IsNil) - - AddToCleanupList(itemName, "mediaImage", vcd.org.Org.Name+"|"+vcd.vdc.Vdc.Name, "Test_UploadMediaImage") - - check.Assert(string(result), Matches, ".*Upload progress 100.00%") - verifyMediaImageUploaded(vcd.vdc, check, itemName) -} - -// Tests System function UploadMediaImage by creating media item and expecting specific error -// then trying to create same media item. As vCD returns cryptic error for such case. -func (vcd *TestVCD) Test_UploadMediaImage_error_withSameItem(check *C) { - fmt.Printf("Running: %s\n", check.TestName()) - - skipWhenMediaPathMissing(vcd, check) - itemName := TestUploadMedia + "4" - - uploadTask, err := vcd.vdc.UploadMediaImage(itemName, "upload from test", vcd.config.Media.MediaPath, 1024) - check.Assert(err, IsNil) - err = uploadTask.WaitTaskCompletion() - check.Assert(err, IsNil) - - AddToCleanupList(itemName, "mediaImage", vcd.org.Org.Name+"|"+vcd.vdc.Vdc.Name, "Test_UploadMediaImage") - - _, err2 := vcd.vdc.UploadMediaImage(itemName, "upload from test", vcd.config.Media.MediaPath, 1024) - check.Assert(err2, NotNil) - check.Assert(err2.Error(), Matches, ".*already exists. Upload with different name.*") -} - // Tests System function Delete by creating media item and // deleting it after. func (vcd *TestVCD) Test_DeleteMedia(check *C) { From 818af08ecd18ca2f5ced22d08ee03e2b15aa8870 Mon Sep 17 00:00:00 2001 From: Dainius S Date: Fri, 21 Aug 2020 08:24:30 +0300 Subject: [PATCH 7/9] [skip ci] Change tense in changelog --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc35466ad..feb3bfd0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,8 +10,8 @@ `OpenApiPostItem`, `OpenApiGetItem`, `OpenApiPutItem`, `OpenApiPutItemSync`, `OpenApiPutItemAsync`, `OpenApiDeleteItem`, `OpenApiIsSupported`, `OpenApiBuildEndpoints` [#325](https://github.com/vmware/go-vcloud-director/pull/325) -* Drop support for VMware Cloud Director 9.5 [#330](https://github.com/vmware/go-vcloud-director/pull/330) -* Deprecate Vdc.UploadMediaImage because it no longer works with API V32.0+ [#330](https://github.com/vmware/go-vcloud-director/pull/330) +* Dropped support for VMware Cloud Director 9.5 [#330](https://github.com/vmware/go-vcloud-director/pull/330) +* Deprecated Vdc.UploadMediaImage because it no longer works with API V32.0+ [#330](https://github.com/vmware/go-vcloud-director/pull/330) ## 2.8.0 (June 30, 2020) From 3e9b47c59b63e612c64ade645debae843b8ccbed Mon Sep 17 00:00:00 2001 From: Dainius S Date: Fri, 21 Aug 2020 09:38:46 +0300 Subject: [PATCH 8/9] Remove one more usage of broken function --- govcd/catalog_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/govcd/catalog_test.go b/govcd/catalog_test.go index 0a9a06197..3618ebcf4 100644 --- a/govcd/catalog_test.go +++ b/govcd/catalog_test.go @@ -449,10 +449,6 @@ func (vcd *TestVCD) Test_CatalogUploadMediaImage_error_withSameItem(check *C) { check.Assert(err, IsNil) AddToCleanupList(itemName, "mediaCatalogImage", vcd.org.Org.Name+"|"+vcd.config.VCD.Catalog.Name, "Test_CatalogUploadMediaImage_error_withSameItem") - - _, err2 := vcd.vdc.UploadMediaImage(itemName, "upload from test", vcd.config.Media.MediaPath, 1024) - check.Assert(err2, NotNil) - check.Assert(err2.Error(), Matches, ".*already exists. Upload with different name.*") } // Tests System function Delete by creating media item and From bd607889804e949b9eef13c7cb277a3da84192e9 Mon Sep 17 00:00:00 2001 From: Dainius S Date: Mon, 24 Aug 2020 10:39:56 +0300 Subject: [PATCH 9/9] Merge master and put changelog note into correct place --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd50473d6..18bcdfd9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ `OpenApiPostItem`, `OpenApiGetItem`, `OpenApiPutItem`, `OpenApiPutItemSync`, `OpenApiPutItemAsync`, `OpenApiDeleteItem`, `OpenApiIsSupported`, `OpenApiBuildEndpoints` [#325](https://github.com/vmware/go-vcloud-director/pull/325) +* Add OVF file upload support in UploadOvf function besides OVA. The input should be OVF file path inside the OVF folder. It will check if input file is XML content type, if yes, skip some OVA steps (like unpacking), if not, keep the old logic. [#323](https://github.com/vmware/go-vcloud-director/pull/323) * Dropped support for VMware Cloud Director 9.5 [#330](https://github.com/vmware/go-vcloud-director/pull/330) * Deprecated Vdc.UploadMediaImage because it no longer works with API V32.0+ [#330](https://github.com/vmware/go-vcloud-director/pull/330) @@ -40,7 +41,6 @@ * Added methods `vapp.UpdateNetworkFirewallRules`, `vapp.UpdateNetworkFirewallRulesAsync`, `vapp.GetVappNetworkById`, `vapp.GetVappNetworkByName` and `vapp.GetVappNetworkByNameOrId` [#308](https://github.com/vmware/go-vcloud-director/pull/308) * Added methods `vapp.UpdateNetworkNatRulesAsync`, `vapp.UpdateNetworkNatRulesAsync`, `vapp.RemoveAllNetworkFirewallRules` and `vapp.RemoveAllNetworkNatRules` [#316](https://github.com/vmware/go-vcloud-director/pull/316) * Added methods `vapp.UpdateNetworkStaticRouting`, `vapp.UpdateNetworkStaticRoutingAsync` and `vapp.RemoveAllNetworkStaticRoutes` [#318](https://github.com/vmware/go-vcloud-director/pull/318) -* Add OVF file upload support in UploadOvf function besides OVA. The input should be OVF file path inside the OVF folder. It will check if input file is XML content type, if yes, skip some OVA steps (like unpacking), if not, keep the old logic. [#323](https://github.com/vmware/go-vcloud-director/pull/323) ## 2.7.0 (April 10,2020)