def test_show_mac_learning_port(self): """ Create port with MAC learning enabled with OS. Test port show api on the MAC enabled port. """ port = self._create_mac_learn_enabled_port(self.network) self.addCleanup(test_utils.call_and_ignore_notfound_exc, self._delete_port, port) nsx_port = self.nsx.get_logical_port(port['name']) nsxport_mac_learning = self._get_nsx_mac_learning_enabled(port) body = self.ports_client.show_port(port['id']) show_port_result = body['port'] # Check the port ID exists and the MAC learning state and name match self.assertIn('id', show_port_result, "Port doesn't have id set") self.assertEqual(nsxport_mac_learning, show_port_result['mac_learning_enabled'], "OS and NSX Mac learning states do not match") self.assertEqual(nsx_port['display_name'], show_port_result['name'], "OS and NSX port names do not match") # from upstream tempest test_show_port() self.assertThat( port, custom_matchers.MatchesDictExceptForKeys( show_port_result, excluded_keys=['extra_dhcp_opts', 'created_at', 'updated_at']))
def cinder_show(self, volume): got_volume = self.volumes_client.show_volume(volume['id'])['volume'] # Exclude updated_at because of bug 1838202. excluded_keys = ['updated_at'] self.assertThat( volume, custom_matchers.MatchesDictExceptForKeys( got_volume, excluded_keys=excluded_keys))
def _update_port_with_security_groups(self, security_groups_names): subnet_1 = self._create_subnet(self.network) fixed_ip_1 = [{'subnet_id': subnet_1['id']}] security_groups_list = list() sec_grps_client = self.security_groups_client for name in security_groups_names: group_create_body = sec_grps_client.create_security_group( name=name) self.addCleanup(test_utils.call_and_ignore_notfound_exc, self.security_groups_client.delete_security_group, group_create_body['security_group']['id']) security_groups_list.append( group_create_body['security_group']['id']) # Create a port sec_grp_name = data_utils.rand_name('secgroup') security_group = sec_grps_client.create_security_group( name=sec_grp_name) self.addCleanup(test_utils.call_and_ignore_notfound_exc, self.security_groups_client.delete_security_group, security_group['security_group']['id']) post_body = { "name": data_utils.rand_name(self.__class__.__name__), "security_groups": [security_group['security_group']['id']], "network_id": self.network['id'], "admin_state_up": True, "fixed_ips": fixed_ip_1 } body = self.ports_client.create_port(**post_body) self.addCleanup(self.ports_client.wait_for_resource_deletion, body['port']['id']) self.addCleanup(test_utils.call_and_ignore_notfound_exc, self.ports_client.delete_port, body['port']['id']) port = body['port'] # Update the port with security groups subnet_2 = self.create_subnet(self.network) fixed_ip_2 = [{'subnet_id': subnet_2['id']}] update_body = { "name": data_utils.rand_name(self.__class__.__name__), "admin_state_up": False, "fixed_ips": fixed_ip_2, "security_groups": security_groups_list } body = self.ports_client.update_port(port['id'], **update_body) port_show = body['port'] # Verify the security groups and other attributes updated to port exclude_keys = set(port_show).symmetric_difference(update_body) exclude_keys.add('fixed_ips') exclude_keys.add('security_groups') self.assertThat( port_show, custom_matchers.MatchesDictExceptForKeys(update_body, exclude_keys)) self.assertEqual(fixed_ip_2[0]['subnet_id'], port_show['fixed_ips'][0]['subnet_id']) for security_group in security_groups_list: self.assertIn(security_group, port_show['security_groups'])
def nova_show(self, server): got_server = (self.servers_client.show_server(server['id']) ['server']) excluded_keys = ['OS-EXT-AZ:availability_zone'] # Exclude these keys because of LP:#1486475 excluded_keys.extend(['OS-EXT-STS:power_state', 'updated']) self.assertThat( server, custom_matchers.MatchesDictExceptForKeys( got_server, excluded_keys=excluded_keys))
def test_show_port(self): # Verify the details of port body = self.client.show_port(self.port['id']) port = body['port'] self.assertIn('id', port) # TODO(Santosh)- This is a temporary workaround to compare create_port # and show_port dict elements.Remove this once extra_dhcp_opts issue # gets fixed in neutron.( bug - 1365341.) self.assertThat(self.port, custom_matchers.MatchesDictExceptForKeys (port, excluded_keys=['extra_dhcp_opts']))
def test_show_port(self): # Verify the details of port body = self.ports_client.show_port(self.port['id']) port = body['port'] self.assertIn('id', port) # NOTE(rfolco): created_at and updated_at may get inconsistent values # due to possible delay between POST request and resource creation. # TODO(rfolco): Neutron Bug #1365341 is fixed, can remove the key # extra_dhcp_opts in the O release (K/L gate jobs still need it). self.assertThat(self.port, custom_matchers.MatchesDictExceptForKeys (port, excluded_keys=['extra_dhcp_opts', 'created_at', 'updated_at']))
def _compare_resource_attrs(self, actual, expected): exclude_keys = set(actual).symmetric_difference(expected) self.assertThat( actual, custom_matchers.MatchesDictExceptForKeys(expected, exclude_keys))
class TestMatchesDictExceptForKeys(base.TestCase, TestMatchersInterface): matches_matcher = custom_matchers.MatchesDictExceptForKeys( { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }, ['c', 'd']) matches_matches = [ { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }, { 'a': 1, 'b': 2, 'c': 5 }, { 'a': 1, 'b': 2 }, ] matches_mismatches = [ {}, { 'foo': 1 }, { 'a': 1, 'b': 3 }, { 'a': 1, 'b': 2, 'foo': 1 }, { 'a': 1, 'b': None, 'foo': 1 }, ] str_examples = [] describe_examples = [("Only in expected:\n" " {'a': 1, 'b': 2}\n", {}, matches_matcher), ("Only in expected:\n" " {'a': 1, 'b': 2}\n" "Only in actual:\n" " {'foo': 1}\n", { 'foo': 1 }, matches_matcher), ("Differences:\n" " b: expected 2, actual 3\n", { 'a': 1, 'b': 3 }, matches_matcher), ("Only in actual:\n" " {'foo': 1}\n", { 'a': 1, 'b': 2, 'foo': 1 }, matches_matcher), ("Only in actual:\n" " {'foo': 1}\n" "Differences:\n" " b: expected 2, actual None\n", { 'a': 1, 'b': None, 'foo': 1 }, matches_matcher)]
def nova_show(self): _, got_server = self.servers_client.get_server(self.server['id']) self.assertThat( self.server, custom_matchers.MatchesDictExceptForKeys( got_server, excluded_keys=['OS-EXT-AZ:availability_zone']))