|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | +""" Test case to check if queryAsyncJobResult returns jobinstanceid |
| 18 | +""" |
| 19 | +from nose.plugins.attrib import attr |
| 20 | +from marvin.cloudstackTestCase import cloudstackTestCase |
| 21 | +from marvin.lib.utils import (cleanup_resources) |
| 22 | +from marvin.lib.base import (Account, |
| 23 | + ServiceOffering, |
| 24 | + VirtualMachine, |
| 25 | + ) |
| 26 | +from marvin.lib.common import (get_domain, |
| 27 | + get_zone, |
| 28 | + get_template, |
| 29 | + ) |
| 30 | + |
| 31 | +from marvin.cloudstackAPI import queryAsyncJobResult |
| 32 | + |
| 33 | + |
| 34 | +class TestJobinstanceid(cloudstackTestCase): |
| 35 | + |
| 36 | + @classmethod |
| 37 | + def setUpClass(cls): |
| 38 | + testClient = super(TestJobinstanceid, cls).getClsTestClient() |
| 39 | + cls.apiclient = testClient.getApiClient() |
| 40 | + cls.testdata = testClient.getParsedTestDataConfig() |
| 41 | + |
| 42 | + cls.hypervisor = cls.testClient.getHypervisorInfo() |
| 43 | + # Get Zone, Domain and templates |
| 44 | + cls.domain = get_domain(cls.apiclient) |
| 45 | + cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) |
| 46 | + |
| 47 | + cls.template = get_template( |
| 48 | + cls.apiclient, |
| 49 | + cls.zone.id, |
| 50 | + cls.testdata["ostype"]) |
| 51 | + |
| 52 | + cls._cleanup = [] |
| 53 | + |
| 54 | + try: |
| 55 | + |
| 56 | + # Create an account |
| 57 | + cls.account = Account.create( |
| 58 | + cls.apiclient, |
| 59 | + cls.testdata["account"], |
| 60 | + domainid=cls.domain.id |
| 61 | + ) |
| 62 | + # Create user api client of the account |
| 63 | + cls.userapiclient = testClient.getUserApiClient( |
| 64 | + UserName=cls.account.name, |
| 65 | + DomainName=cls.account.domain |
| 66 | + ) |
| 67 | + |
| 68 | + # Create Service offering |
| 69 | + cls.service_offering = ServiceOffering.create( |
| 70 | + cls.apiclient, |
| 71 | + cls.testdata["service_offering"], |
| 72 | + ) |
| 73 | + |
| 74 | + cls._cleanup = [ |
| 75 | + cls.account, |
| 76 | + cls.service_offering, |
| 77 | + ] |
| 78 | + except Exception as e: |
| 79 | + cls.tearDownClass() |
| 80 | + raise e |
| 81 | + return |
| 82 | + |
| 83 | + @classmethod |
| 84 | + def tearDownClass(cls): |
| 85 | + try: |
| 86 | + cleanup_resources(cls.apiclient, cls._cleanup) |
| 87 | + except Exception as e: |
| 88 | + raise Exception("Warning: Exception during cleanup : %s" % e) |
| 89 | + |
| 90 | + def setUp(self): |
| 91 | + self.apiclient = self.testClient.getApiClient() |
| 92 | + self.dbclient = self.testClient.getDbConnection() |
| 93 | + self.cleanup = [] |
| 94 | + |
| 95 | + def tearDown(self): |
| 96 | + try: |
| 97 | + cleanup_resources(self.apiclient, self.cleanup) |
| 98 | + except Exception as e: |
| 99 | + raise Exception("Warning: Exception during cleanup : %s" % e) |
| 100 | + return |
| 101 | + |
| 102 | + @attr(tags=["advanced", "basic"], required_hardware="false") |
| 103 | + def test_queryAsyncJobResult_jobinstanceid(self): |
| 104 | + """ Test queryAsyncJobResult api return jobinstanceid |
| 105 | +
|
| 106 | + # 1. Deploy a VM |
| 107 | + # 2. Call queryAsyncJobResult API with jobid of previous step |
| 108 | + # 3. Verify that queryAsyncJobResult returns jobinstanceid |
| 109 | +
|
| 110 | + """ |
| 111 | + # Step 1 |
| 112 | + |
| 113 | + vm = VirtualMachine.create( |
| 114 | + self.userapiclient, |
| 115 | + self.testdata["small"], |
| 116 | + templateid=self.template.id, |
| 117 | + accountid=self.account.name, |
| 118 | + domainid=self.account.domainid, |
| 119 | + serviceofferingid=self.service_offering.id, |
| 120 | + zoneid=self.zone.id, |
| 121 | + ) |
| 122 | + |
| 123 | + # Step 2 |
| 124 | + cmd = queryAsyncJobResult.queryAsyncJobResultCmd() |
| 125 | + cmd.jobid = vm.jobid |
| 126 | + result = self.apiclient.queryAsyncJobResult(cmd) |
| 127 | + |
| 128 | + # Step 3 |
| 129 | + self.assertTrue( |
| 130 | + "jobinstanceid" in dir(result), |
| 131 | + "Check if jobinstanceid is returned by queryAsyncJobResult API") |
| 132 | + |
| 133 | + return |
0 commit comments