def test_role_lifecycle_create(self): """ Tests normal lifecycle operations for roles """ # Reuse self.role created in setUp() try: role = Role.create( self.apiclient, self.testdata["role"] ) self.fail("An exception was expected when creating duplicate roles") except CloudstackAPIException: pass list_roles = Role.list(self.apiclient, id=self.role.id) self.assertEqual( isinstance(list_roles, list), True, "List Roles response was not a valid list" ) self.assertEqual( len(list_roles), 1, "List Roles response size was not 1" ) self.assertEqual( list_roles[0].name, self.testdata["role"]["name"], msg="Role name does not match the test data" ) self.assertEqual( list_roles[0].type, self.testdata["role"]["type"], msg="Role type does not match the test data" )
def test_role_lifecycle_import(self): """ Tests import role with the rules """ # use importrole from testdata self.testdata["importrole"]["name"] += self.getRandomString() try: role_imported = Role.importRole(self.apiclient, self.testdata["importrole"]) self.cleanup.append(role_imported) except CloudstackAPIException as e: self.fail("Failed to import the role: %s" % e) list_role_imported = Role.list(self.apiclient, id=role_imported.id) self.assertEqual(isinstance(list_role_imported, list), True, "List Roles response was not a valid list") self.assertEqual(len(list_role_imported), 1, "List Roles response size was not 1") self.assertEqual(list_role_imported[0].name, self.testdata["importrole"]["name"], msg="Role name does not match the test data") self.assertEqual(list_role_imported[0].type, self.testdata["importrole"]["type"], msg="Role type does not match the test data") self.validate_permissions_dict(self.testdata["importrole"]["rules"], role_imported.id)
def test_role_lifecycle_clone(self): """ Tests create role from existing role """ # Use self.role created in setUp() role_to_be_cloned = { "name": "MarvinFake Clone Role ", "roleid": self.role.id, "description": "Fake Role cloned by Marvin test" } try: role_cloned = Role.create(self.apiclient, role_to_be_cloned) self.cleanup.append(role_cloned) except CloudstackAPIException as e: self.fail("Failed to create the role: %s" % e) list_role_cloned = Role.list(self.apiclient, id=role_cloned.id) self.assertEqual(isinstance(list_role_cloned, list), True, "List Roles response was not a valid list") self.assertEqual(len(list_role_cloned), 1, "List Roles response size was not 1") self.assertEqual(list_role_cloned[0].name, role_to_be_cloned["name"], msg="Role name does not match the test data") self.assertEqual(list_role_cloned[0].type, self.testdata["role"]["type"], msg="Role type does not match the test data") list_rolepermissions = RolePermission.list(self.apiclient, roleid=self.role.id) self.validate_permissions_list(list_rolepermissions, role_cloned.id)
def setUp(self): self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() self.testdata = TestData().testdata feature_enabled = self.apiclient.listCapabilities(listCapabilities.listCapabilitiesCmd()).dynamicrolesenabled if not feature_enabled: self.skipTest("Dynamic Role-Based API checker not enabled, skipping test") self.testdata["role"]["name"] += self.getRandomString() self.role = Role.create( self.apiclient, self.testdata["role"] ) self.testdata["rolepermission"]["roleid"] = self.role.id self.rolepermission = RolePermission.create( self.apiclient, self.testdata["rolepermission"] ) self.account = Account.create( self.apiclient, self.testdata["account"], roleid=self.role.id ) self.cleanup = [ self.account, self.rolepermission, self.role ]
def test_role_lifecycle_delete(self): """ Tests role update """ self.account.delete(self.apiclient) self.role.delete(self.apiclient) list_roles = Role.list(self.apiclient, id=self.role.id) self.assertEqual(list_roles, None, "List Roles response should be empty")
def test_role_lifecycle_delete(self): """ Tests role update """ self.account.delete(self.apiclient) self.role.delete(self.apiclient) list_roles = Role.list(self.apiclient, id=self.role.id) self.assertEqual( list_roles, None, "List Roles response should be empty" )
def test_role_lifecycle_update(self): """ Tests role update """ self.account.delete(self.apiclient) new_role_name = self.getRandomRoleName() self.role.update(self.apiclient, name=new_role_name, type='Admin') update_role = Role.list(self.apiclient, id=self.role.id)[0] self.assertEqual(update_role.name, new_role_name, msg="Role name does not match updated role name") self.assertEqual(update_role.type, 'Admin', msg="Role type does not match updated role type")
def test_role_lifecycle_update_role_inuse(self): """ Tests role update when role is in use by an account """ new_role_name = self.getRandomRoleName() try: self.role.update(self.apiclient, name=new_role_name, type='Admin') self.fail("Updation of role type is not allowed when role is in use") except CloudstackAPIException: pass self.role.update(self.apiclient, name=new_role_name) update_role = Role.list(self.apiclient, id=self.role.id)[0] self.assertEqual( update_role.name, new_role_name, msg="Role name does not match updated role name" )
def test_role_lifecycle_update_role_inuse(self): """ Tests role update when role is in use by an account """ new_role_name = self.getRandomRoleName() try: self.role.update(self.apiclient, name=new_role_name, type='Admin') self.fail( "Updation of role type is not allowed when role is in use") except CloudstackAPIException: pass self.role.update(self.apiclient, name=new_role_name) update_role = Role.list(self.apiclient, id=self.role.id)[0] self.assertEqual(update_role.name, new_role_name, msg="Role name does not match updated role name")
def test_role_lifecycle_update(self): """ Tests role update """ self.account.delete(self.apiclient) new_role_name = self.getRandomRoleName() self.role.update(self.apiclient, name=new_role_name, type='Admin') update_role = Role.list(self.apiclient, id=self.role.id)[0] self.assertEqual( update_role.name, new_role_name, msg="Role name does not match updated role name" ) self.assertEqual( update_role.type, 'Admin', msg="Role type does not match updated role type" )
def test_role_lifecycle_list(self): """ Tests that default four roles exist """ roleTypes = { 1: "Admin", 2: "ResourceAdmin", 3: "DomainAdmin", 4: "User" } for idx in range(1, 5): list_roles = Role.list(self.apiclient, id=idx) self.assertEqual(isinstance(list_roles, list), True, "List Roles response was not a valid list") self.assertEqual(len(list_roles), 1, "List Roles response size was not 1") self.assertEqual(list_roles[0].type, roleTypes[idx], msg="Default role type differs from expectation")
def test_role_lifecycle_list(self): """ Tests that default four roles exist """ roleTypes = {1: "Admin", 2: "ResourceAdmin", 3: "DomainAdmin", 4: "User"} for idx in range(1,5): list_roles = Role.list(self.apiclient, id=idx) self.assertEqual( isinstance(list_roles, list), True, "List Roles response was not a valid list" ) self.assertEqual( len(list_roles), 1, "List Roles response size was not 1" ) self.assertEqual( list_roles[0].type, roleTypes[idx], msg="Default role type differs from expectation" )
def setUpClass(cls): cls.spapi = spapi.Api.fromConfig(multiCluster=True) testClient = super(TestStoragePool, cls).getClsTestClient() cls.apiclient = testClient.getApiClient() cls.userapiclient = testClient.getUserApiClient( UserName="******", DomainName="ROOT") cls.unsupportedHypervisor = False cls.hypervisor = testClient.getHypervisorInfo() if cls.hypervisor.lower() in ("hyperv", "lxc"): cls.unsupportedHypervisor = True return cls.services = testClient.getParsedTestDataConfig() # Get Zone, Domain and templates cls.domain = get_domain(cls.apiclient) cls.zone = None zones = list_zones(cls.apiclient) for z in zones: if z.internaldns1 == cls.getClsConfig().mgtSvr[0].mgtSvrIp: cls.zone = z storpool_primary_storage = { "name": "ssd", "zoneid": cls.zone.id, "url": "ssd", "scope": "zone", "capacitybytes": 4500000, "capacityiops": 155466464221111121, "hypervisor": "kvm", "provider": "StorPool", "tags": "ssd" } storpool_service_offerings = { "name": "ssd", "displaytext": "SP_CO_2 (Min IOPS = 10,000; Max IOPS = 15,000)", "cpunumber": 1, "cpuspeed": 500, "memory": 512, "storagetype": "shared", "customizediops": False, "hypervisorsnapshotreserve": 200, "tags": "ssd" } storage_pool = list_storage_pools(cls.apiclient, name='ssd') service_offerings = list_service_offering(cls.apiclient, name='ssd') disk_offerings = list_disk_offering(cls.apiclient, name="Small") cls.disk_offerings = disk_offerings[0] if storage_pool is None: storage_pool = StoragePool.create(cls.apiclient, storpool_primary_storage) else: storage_pool = storage_pool[0] cls.storage_pool = storage_pool cls.debug(pprint.pformat(storage_pool)) if service_offerings is None: service_offerings = ServiceOffering.create( cls.apiclient, storpool_service_offerings) else: service_offerings = service_offerings[0] template = get_template(cls.apiclient, cls.zone.id, account="system") if template == FAILED: assert False, "get_template() failed to return template\ with description %s" % cls.services["ostype"] cls.services["domainid"] = cls.domain.id cls.services["small"]["zoneid"] = cls.zone.id cls.services["templates"]["ostypeid"] = template.ostypeid cls.services["zoneid"] = cls.zone.id cls.service_offering = service_offerings user = list_users(cls.apiclient, account='StorPoolUser', domainid=cls.domain.id) account = list_accounts(cls.apiclient, id=user[0].accountid) if account is None: role = Role.list(cls.apiclient, name='User') cmd = createAccount.createAccountCmd() cmd.email = '*****@*****.**' cmd.firstname = 'StorPoolUser' cmd.lastname = 'StorPoolUser' cmd.password = '******' cmd.username = '******' cmd.roleid = role[0].id account = cls.apiclient.createAccount(cmd) else: account = account[0] cls.account = account # cls.tmp_files = [] # cls.keypair = SSHKeyPair.create( # cls.apiclient, # name=random_gen() + ".pem", # account=cls.account.name, # domainid=cls.account.domainid) # # keyPairFilePath = tempfile.gettempdir() + os.sep + cls.keypair.name # # Clenaup at end of execution # cls.tmp_files.append(keyPairFilePath) # # cls.debug("File path: %s" % keyPairFilePath) # # f = open(keyPairFilePath, "w+") # f.write(cls.keypair.privatekey) # f.close() # # os.system("chmod 400 " + keyPairFilePath) # # cls.keyPairFilePath = keyPairFilePath cls.volume_1 = Volume.create( cls.userapiclient, {"diskname": "StorPoolDisk-1"}, zoneid=cls.zone.id, diskofferingid=cls.disk_offerings.id, ) cls.volume_2 = Volume.create( cls.userapiclient, {"diskname": "StorPoolDisk-2"}, zoneid=cls.zone.id, diskofferingid=cls.disk_offerings.id, ) cls.volume = Volume.create( cls.userapiclient, {"diskname": "StorPoolDisk-3"}, zoneid=cls.zone.id, diskofferingid=cls.disk_offerings.id, ) cls.virtual_machine = VirtualMachine.create( cls.userapiclient, {"name": "StorPool-%s" % uuid.uuid4()}, zoneid=cls.zone.id, templateid=template.id, serviceofferingid=cls.service_offering.id, hypervisor=cls.hypervisor, rootdisksize=10, ) cls.virtual_machine2 = VirtualMachine.create( cls.userapiclient, {"name": "StorPool-%s" % uuid.uuid4()}, zoneid=cls.zone.id, templateid=template.id, serviceofferingid=cls.service_offering.id, hypervisor=cls.hypervisor, rootdisksize=10, ) cls.template = template cls.random_data_0 = random_gen(size=100) cls.test_dir = "/tmp" cls.random_data = "random.data" cls._cleanup = [] cls._cleanup.append(cls.virtual_machine) cls._cleanup.append(cls.virtual_machine2) cls._cleanup.append(cls.volume_1) cls._cleanup.append(cls.volume_2) cls._cleanup.append(cls.volume) return