def setUpClass(cls): """ Creating an instance for smoke testing """ super(RBACTest, cls).setUpClass() cls.dbaas_admin = cls.dbaas_provider.admin_client.reddwarfclient cls.dbaas_admin.authenticate() resp, body = RBACTest.dbaas_admin.client.last_response j = json.loads(body) role = j['access']['user']['roles'][0]['name'] assert (role == DBaaSFixture.Role.admin) cls.dbaas_creator = cls.dbaas_provider.creator_client.reddwarfclient cls.dbaas_creator.authenticate() resp, body = cls.dbaas_creator.client.last_response j = json.loads(body) role = j['access']['user']['roles'][0]['name'] assert (role == DBaaSFixture.Role.creator) cls.dbaas_observer = cls.dbaas_provider.observer_client.reddwarfclient cls.dbaas_observer.authenticate() resp, body = cls.dbaas_observer.client.last_response j = json.loads(body) role = j['access']['user']['roles'][0]['name'] assert (role == DBaaSFixture.Role.observer) cls.admin_instance_id, time = testutil.create_active_instance(cls.dbaas_admin) cls.creator_instance_id, time = testutil.create_active_instance(cls.dbaas_creator)
def test_usage_08_duplicate_create(self): """ Delete one instance then recreate it, ensure separate AH events """ tc_name = "Usage 08 tests" tc_num = 8 instance_id = self.instance_id_list[0] inst_name = self.client.instances.get(instance_id).name # delete the existing instance if testutil.getInstanceStatus(self.client, instance_id) == "ACTIVE": self.client.instances.get(instance_id).delete() self.instance_id_list.remove(instance_id) duration = datetime.utcnow() - self.starttime_list[tc_num] rootAction = "reddwarf.instance.delete" # AH Event Sent - Check AH data data AFTER the DELETE time.sleep(self.AHDELAY) AHEventsList = self.dbaas_atomhopper_provider.events_by_resourceId(instance_id) single_event = [event for event in AHEventsList if event.rootAction == rootAction].pop() self.assertEqual( single_event.resourceId, instance_id, "AH resourceID:%r != created instanceID:%r" % (single_event.resourceId, instance_id), ) testutil.valid_duration(duration, single_event, self.dateFormat) # now create an exact duplicate instance startTime1 = datetime.utcnow() instance_id1, elapsed_time = testutil.create_active_instance( self.client, name=inst_name, flavor_id=2, volume={"size": 2}, databases=[{"name": "db_name"}] ) httpCode = testutil.get_last_response_code(self.client) if httpCode != "200": raise Exception("Create instance failed with code %s" % httpCode) self.fixture_log.debug( "Inst: %r is: %r after: %r seconds" % (instance_id, self.client.instances.get(instance_id).status, elapsed_time) ) running_time = (datetime.utcnow() - self.starttime_list[tc_num]).seconds if 5 * self.ONEMIN > running_time: time.sleep((5 * self.ONEMIN) - running_time) # delete the ACTIVE instance if testutil.getInstanceStatus(self.client, instance_id1) == "ACTIVE": self.client.instances.get(instance_id1).delete() duration = datetime.utcnow() - self.starttime_list[tc_num] rootAction = "reddwarf.instance.delete" # AH Event Sent - Check AH data data AFTER the DELETE time.sleep(self.AHDELAY) AHEventsList = self.dbaas_atomhopper_provider.events_by_resourceId(instance_id1) single_event = [event for event in AHEventsList if event.rootAction == rootAction].pop() self.assertEqual( single_event.resourceId, instance_id1, "AH resourceID:%r != created instanceID:%r" % (single_event.resourceId, instance_id1), ) testutil.valid_duration(duration, single_event, self.dateFormat)
def test_rbac_instance_observer_rights(self): next_flavor = 1 resize_vol = 5 try: # list instances self.dbaas_observer.instances.list() httpCode = testutil.get_last_response_code(self.dbaas_observer) self.assertTrue(httpCode == '200', "DB list: Expected http code: %s | Actual http code: %s " % ('200', httpCode)) # list instance details self.dbaas_observer.instances.get(self.creator_instance_id) httpCode = testutil.get_last_response_code(self.dbaas_observer) self.assertTrue(httpCode == '200', "DB list get ID: Expected http code: %s | Actual http code: %s " % ('200', httpCode)) except Exception as e: self.fail(e) try: testutil.create_active_instance(self.dbaas_observer) except Exception as e: httpCode = testutil.get_last_response_code(self.dbaas_observer) self.assertTrue(httpCode == '405', "Instance Create: Expected http code: %s | Actual http code: %s " % ('405', httpCode)) try: self.dbaas_observer.instances.get(self.creator_instance_id).delete() except Exception as e: httpCode = testutil.get_last_response_code(self.dbaas_observer) self.assertTrue(httpCode == '405', "Instance Delete: Expected http code: %s | Actual http code: %s " % ('405', httpCode)) try: # resize instance self.dbaas_observer.instances.resize_instance(self.creator_instance_id, next_flavor) except Exception as e: httpCode = testutil.get_last_response_code(self.dbaas_observer) self.assertTrue(httpCode == '405', "Resize Instance: Expected http code: %s | Actual http code: %s " % ('405', httpCode)) try: #restart instance self.dbaas_observer.instances.restart(self.creator_instance_id) except Exception as e: httpCode = testutil.get_last_response_code(self.dbaas_observer) self.assertTrue(httpCode == '405', "Restart Instance: Expected http code: %s | Actual http code: %s " % ('405', httpCode)) try: #resize instance volume self.dbaas_observer.instances.resize_volume(self.creator_instance_id, resize_vol) except Exception as e: httpCode = testutil.get_last_response_code(self.dbaas_observer) self.assertTrue(httpCode == '405', "Resize Volume: Expected http code: %s | Actual http code: %s " % ('405', httpCode))