def mgmt_instance_get(): """ Tests the mgmt instances index method. """ reqs = Requirements(is_admin=True) user = CONFIG.users.find_user(reqs) client = create_dbaas_client(user) mgmt = client.management # Grab the info.id created by the main instance test which is stored in # a global. id = instance_info.id api_instance = mgmt.show(id) # Print out all fields for extra info if the test fails. for name in dir(api_instance): print(str(name) + "=" + str(getattr(api_instance, name))) with TypeCheck("instance", api_instance) as instance: instance.has_field('created', basestring) instance.has_field('deleted', bool) # If the instance hasn't been deleted, this should be false... but # lets avoid creating more ordering work. instance.has_field('deleted_at', (basestring, None)) instance.has_field('flavor', dict, flavor_check) instance.has_field('guest_status', dict, guest_status_check) instance.has_field('id', basestring) instance.has_field('links', list) instance.has_field('name', basestring) #instance.has_field('server_status', basestring) instance.has_field('status', basestring) instance.has_field('tenant_id', basestring) instance.has_field('updated', basestring) # Can be None if no volume is given on this instance. if CONFIG.trove_volume_support: instance.has_field('volume', dict, volume_check) else: instance.has_field('volume', None) #TODO(tim-simpson): Validate additional fields, assert # no extra fields exist. with CollectionCheck("server", api_instance.server) as server: server.has_element("addresses", dict) server.has_element("deleted", bool) server.has_element("deleted_at", (basestring, None)) server.has_element("host", basestring) server.has_element("id", basestring) server.has_element("local_id", int) server.has_element("name", basestring) server.has_element("status", basestring) server.has_element("tenant_id", basestring) if (CONFIG.trove_volume_support and CONFIG.trove_main_instance_has_volume): with CollectionCheck("volume", api_instance.volume) as volume: volume.has_element("attachments", list) volume.has_element("availability_zone", basestring) volume.has_element("created_at", (basestring, None)) volume.has_element("id", basestring) volume.has_element("size", int) volume.has_element("status", basestring)
def test_configurations_get(self): # test that the instance shows up on the assigned configuration result = instance_info.dbaas.configurations.get(configuration_info.id) assert_equal(configuration_info.id, result.id) assert_equal(configuration_info.name, result.name) assert_equal(configuration_info.description, result.description) # check the result field types with TypeCheck("configuration", result) as check: check.has_field("id", basestring) check.has_field("name", basestring) check.has_field("description", basestring) check.has_field("values", dict) print(result.values) with CollectionCheck("configuration_values", result.values) as check: # check each item has the correct type according to the rules for (item_key, item_val) in result.values.iteritems(): print("item_key: %s" % item_key) print("item_val: %s" % item_val) dbaas = instance_info.dbaas param = dbaas.configuration_parameters.get_parameter( instance_info.dbaas_datastore, instance_info.dbaas_datastore_version, item_key) if param.type == 'integer': check.has_element(item_key, int) if param.type == 'string': check.has_element(item_key, basestring) if param.type == 'boolean': check.has_element(item_key, bool) # Test to make sure that another user is not able to GET this config reqs = Requirements(is_admin=False) test_auth_user = instance_info.user.auth_user other_user = CONFIG.users.find_user(reqs, black_list=[test_auth_user]) other_user_tenant_id = other_user.tenant_id client_tenant_id = instance_info.user.tenant_id if other_user_tenant_id == client_tenant_id: other_user = CONFIG.users.find_user(reqs, black_list=[ instance_info.user.auth_user, other_user]) print(other_user) print(other_user.__dict__) other_client = create_dbaas_client(other_user) assert_raises(exceptions.NotFound, other_client.configurations.get, configuration_info.id)
def assert_configuration_show(self, config_id, config_name): result = self.auth_client.configurations.get(config_id) self.assert_equal(config_id, result.id, "Unexpected config id") self.assert_equal(config_name, result.name, "Unexpected config name") # check the result field types with TypeCheck("configuration", result) as check: check.has_field("id", basestring) check.has_field("name", basestring) check.has_field("description", basestring) check.has_field("values", dict) check.has_field("created", basestring) check.has_field("updated", basestring) check.has_field("instance_count", int) # check for valid timestamps self.assert_true(self._is_valid_timestamp(result.created), 'Created timestamp %s is invalid' % result.created) self.assert_true(self._is_valid_timestamp(result.updated), 'Updated timestamp %s is invalid' % result.updated) with CollectionCheck("configuration_values", result.values) as check: # check each item has the correct type according to the rules for (item_key, item_val) in result.values.iteritems(): print("item_key: %s" % item_key) print("item_val: %s" % item_val) param = ( self.auth_client.configuration_parameters.get_parameter( self.instance_info.dbaas_datastore, self.instance_info.dbaas_datastore_version, item_key)) if param.type == 'integer': check.has_element(item_key, int) if param.type == 'string': check.has_element(item_key, basestring) if param.type == 'boolean': check.has_element(item_key, bool)
def volume_check(volume): with CollectionCheck("volume", volume) as check: check.has_element("id", six.string_types) check.has_element("size", int) check.has_element("used", float) check.has_element("total", float)
def guest_status_check(guest_status): with CollectionCheck("guest_status", guest_status) as check: check.has_element("state_description", six.string_types)
def datastore_check(datastore): with CollectionCheck("datastore", datastore) as check: check.has_element("type", six.string_types) check.has_element("version", six.string_types)
def flavor_check(flavor): with CollectionCheck("flavor", flavor) as check: check.has_element("id", six.string_types) check.has_element("links", list)
def flavor_check(flavor): with CollectionCheck("flavor", flavor) as check: check.has_element("id", basestring) check.has_element("links", list)
def test_configurations_get(self): """test that the instance shows up on the assigned configuration""" result = instance_info.dbaas.configurations.get(configuration_info.id) assert_equal(configuration_info.id, result.id) assert_equal(configuration_info.name, result.name) assert_equal(configuration_info.description, result.description) # check the result field types with TypeCheck("configuration", result) as check: check.has_field("id", six.string_types) check.has_field("name", six.string_types) check.has_field("description", six.string_types) check.has_field("values", dict) check.has_field("created", six.string_types) check.has_field("updated", six.string_types) check.has_field("instance_count", int) print(result.values) # check for valid timestamps assert_true(_is_valid_timestamp(result.created)) assert_true(_is_valid_timestamp(result.updated)) # check that created and updated timestamps differ, since # test_appending_to_existing_configuration should have changed the # updated timestamp if not CONFIG.fake_mode: assert_not_equal(result.created, result.updated) assert_equal(result.instance_count, 1) with CollectionCheck("configuration_values", result.values) as check: # check each item has the correct type according to the rules for (item_key, item_val) in result.values.items(): print("item_key: %s" % item_key) print("item_val: %s" % item_val) dbaas = instance_info.dbaas param = dbaas.configuration_parameters.get_parameter( instance_info.dbaas_datastore, instance_info.dbaas_datastore_version, item_key) if param.type == 'integer': check.has_element(item_key, int) if param.type == 'string': check.has_element(item_key, six.string_types) if param.type == 'boolean': check.has_element(item_key, bool) # Test to make sure that another user is not able to GET this config reqs = Requirements(is_admin=False) test_auth_user = instance_info.user.auth_user other_user = CONFIG.users.find_user(reqs, black_list=[test_auth_user]) other_user_tenant_id = other_user.tenant_id client_tenant_id = instance_info.user.tenant_id if other_user_tenant_id == client_tenant_id: other_user = CONFIG.users.find_user( reqs, black_list=[instance_info.user.auth_user, other_user]) print(other_user) print(other_user.__dict__) other_client = create_dbaas_client(other_user) assert_raises(exceptions.NotFound, other_client.configurations.get, configuration_info.id)
def volume_check(volume): with CollectionCheck("volume", volume) as check: check.has_element("id", basestring) check.has_element("size", int) check.has_element("used", float)