def test_update_port_mixed_ops_integrity(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()
        extra = {'key1': 'value1', 'key2': 'value2'}

        _, port = self.create_port(node_id=node_id, address=address,
                                   extra=extra)
        port_id = port['uuid']

        new_address = data_utils.rand_mac_address()
        new_extra = {'key1': 'new-value1', 'key3': 'new-value3'}

        patch = [{'path': '/address',
                  'op': 'replace',
                  'value': new_address},
                 {'path': '/extra/key1',
                  'op': 'replace',
                  'value': new_extra['key1']},
                 {'path': '/extra/key2',
                  'op': 'remove'},
                 {'path': '/extra/key3',
                  'op': 'add',
                  'value': new_extra['key3']},
                 {'path': '/nonexistent',
                  'op': 'replace',
                  'value': 'value'}]

        self.assertRaises(exc.BadRequest, self.client.update_port, port_id,
                          patch)

        # patch should not be applied
        _, body = self.client.show_port(port_id)
        self.assertEqual(address, body['address'])
        self.assertEqual(extra, body['extra'])
Example #2
0
    def test_update_port_replace(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()
        extra = {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}

        port_id = self.create_port(node_id=node_id, address=address,
                                   extra=extra)['port']['uuid']

        new_address = data_utils.rand_mac_address()
        new_extra = {'key1': 'new-value1', 'key2': 'new-value2',
                     'key3': 'new-value3'}

        patch = [{'path': '/address',
                  'op': 'replace',
                  'value': new_address},
                 {'path': '/extra/key1',
                  'op': 'replace',
                  'value': new_extra['key1']},
                 {'path': '/extra/key2',
                  'op': 'replace',
                  'value': new_extra['key2']},
                 {'path': '/extra/key3',
                  'op': 'replace',
                  'value': new_extra['key3']}]

        self.client.update_port(port_id, patch)

        resp, body = self.client.show_port(port_id)
        self.assertEqual(200, resp.status)
        self.assertEqual(new_address, body['address'])
        self.assertEqual(new_extra, body['extra'])
    def test_update_port_mixed_ops(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()
        extra = {'key1': 'value1', 'key2': 'value2'}

        _, port = self.create_port(node_id=node_id, address=address,
                                   extra=extra)

        new_address = data_utils.rand_mac_address()
        new_extra = {'key1': 'new-value1', 'key3': 'new-value3'}

        patch = [{'path': '/address',
                  'op': 'replace',
                  'value': new_address},
                 {'path': '/extra/key1',
                  'op': 'replace',
                  'value': new_extra['key1']},
                 {'path': '/extra/key2',
                  'op': 'remove'},
                 {'path': '/extra/key3',
                  'op': 'add',
                  'value': new_extra['key3']}]

        self.client.update_port(port['uuid'], patch)

        _, body = self.client.show_port(port['uuid'])
        self.assertEqual(new_address, body['address'])
        self.assertEqual(new_extra, body['extra'])
Example #4
0
    def test_rand_mac_address(self):
        actual = data_utils.rand_mac_address()
        self.assertIsInstance(actual, str)
        self.assertRegexpMatches(actual, "^([0-9a-f][0-9a-f]:){5}"
                                         "[0-9a-f][0-9a-f]$")

        actual2 = data_utils.rand_mac_address()
        self.assertNotEqual(actual, actual2)
Example #5
0
    def test_list_ports_details_with_address(self):
        node_id = self.node["uuid"]
        address = data_utils.rand_mac_address()
        self.create_port(node_id=node_id, address=address)
        for i in range(0, 5):
            self.create_port(node_id=node_id, address=data_utils.rand_mac_address())

        _, body = self.client.list_ports_detail(address=address)
        self.assertEqual(1, len(body["ports"]))
        self.assertEqual(address, body["ports"][0]["address"])
    def test_update_port_malformed_port_uuid(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()

        self.create_port(node_id=node_id, address=address)

        new_address = data_utils.rand_mac_address()
        self.assertRaises(exc.BadRequest, self.client.update_port,
                          uuid='malformed:uuid',
                          patch=[{'path': '/address', 'op': 'replace',
                                  'value': new_address}])
Example #7
0
    def test_list_ports_details_with_address(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()
        self.create_port(node_id=node_id, address=address)
        for i in range(0, 5):
            self.create_port(node_id=node_id,
                             address=data_utils.rand_mac_address())

        resp, body = self.client.list_ports_detail(address=address)
        self.assertEqual(200, resp.status)
        self.assertEqual(1, len(body['ports']))
        self.assertEqual(address, body['ports'][0]['address'])
    def test_update_port_replace_mac_with_duplicated(self):
        node_id = self.node['uuid']
        address1 = data_utils.rand_mac_address()
        address2 = data_utils.rand_mac_address()

        self.create_port(node_id=node_id, address=address1)
        port_id = self.create_port(node_id=node_id,
                                   address=address2)['port']['uuid']
        patch = [{'path': '/address',
                  'op': 'replace',
                  'value': address1}]
        self.assertRaises(exc.Conflict,
                          self.client.update_port, port_id, patch)
 def test_create_port_duplicated_mac(self):
     node_id = self.node['uuid']
     address = data_utils.rand_mac_address()
     self.create_port(node_id=node_id, address=address)
     self.assertRaises(exc.Conflict,
                       self.create_port, node_id=node_id,
                       address=address)
Example #10
0
 def test_dhcpv6_stateless_two_subnets(self):
     """When 2 subnets configured with dnsmasq SLAAC and DHCP stateless
     and there is radvd, port shall receive IP addresses calculated
     from its MAC and mask of subnet from both subnets.
     """
     for ra_mode, add_mode in (
             ('slaac', 'slaac'),
             ('dhcpv6-stateless', 'dhcpv6-stateless'),
     ):
         kwargs = {'ipv6_ra_mode': ra_mode,
                   'ipv6_address_mode': add_mode}
         subnet1 = self.create_subnet(self.network, **kwargs)
         subnet2 = self.create_subnet(self.network, **kwargs)
         port_mac = data_utils.rand_mac_address()
         port = self.create_port(self.network, mac_address=port_mac)
         real_ips = [i['ip_address'] for i in port['fixed_ips']]
         eui_ips = [
             data_utils.get_ipv6_addr_by_EUI64(i['cidr'],
                                               port_mac).format()
             for i in (subnet1, subnet2)
         ]
         self._clean_network()
         self.assertSequenceEqual(sorted(real_ips), sorted(eui_ips),
                                  ('Real port IPs %s,%s are not equal to'
                                   ' SLAAC IPs: %s,%s') % tuple(real_ips +
                                                                eui_ips))
    def test_create_port_malformed_port_uuid(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()
        uuid = 'malformed:uuid'

        self.assertRaises(exc.BadRequest, self.create_port, node_id=node_id,
                          address=address, uuid=uuid)
 def test_create_port_malformed_extra(self):
     node_id = self.node['uuid']
     address = data_utils.rand_mac_address()
     extra = {'key': 0.123}
     self.assertRaises(exc.BadRequest,
                       self.create_port, node_id=node_id,
                       address=address, extra=extra)
    def test_update_port_remove(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()
        extra = {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}

        _, port = self.create_port(node_id=node_id, address=address,
                                   extra=extra)

        # Removing one item from the collection
        self.client.update_port(port['uuid'],
                                [{'path': '/extra/key2',
                                 'op': 'remove'}])
        extra.pop('key2')
        _, body = self.client.show_port(port['uuid'])
        self.assertEqual(extra, body['extra'])

        # Removing the collection
        self.client.update_port(port['uuid'], [{'path': '/extra',
                                               'op': 'remove'}])
        _, body = self.client.show_port(port['uuid'])
        self.assertEqual({}, body['extra'])

        # Assert nothing else was changed
        self.assertEqual(node_id, body['node_uuid'])
        self.assertEqual(address, body['address'])
    def setUp(self):
        super(TestPorts, self).setUp()

        _, self.chassis = self.create_chassis()
        _, self.node = self.create_node(self.chassis['uuid'])
        _, self.port = self.create_port(self.node['uuid'],
                                        data_utils.rand_mac_address())
    def test_update_port_remove_nonexistent_property(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()

        port_id = self.create_port(node_id=node_id, address=address)['port'][
            'uuid']
        self.assertRaises(exc.BadRequest, self.client.update_port, port_id,
                          [{'path': '/nonexistent', 'op': 'remove'}])
    def test_update_port_remove_mandatory_field_port_uuid(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()

        port_id = self.create_port(node_id=node_id, address=address)['port'][
            'uuid']
        self.assertRaises(exc.BadRequest, self.client.update_port, port_id,
                          [{'path': '/uuid', 'op': 'remove'}])
Example #17
0
    def test_create_port(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()

        port = self.create_port(node_id=node_id, address=address)['port']

        self.assertEqual(port['address'], address)
        self.assertEqual(port['node_uuid'], node_id)
    def test_delete_port(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()
        _, port = self.create_port(node_id=node_id, address=address)

        self.delete_port(port['uuid'])

        self.assertRaises(exc.NotFound, self.client.show_port, port['uuid'])
    def test_update_port_replace_mac_with_duplicated(self):
        node_id = self.node['uuid']
        address1 = data_utils.rand_mac_address()
        address2 = data_utils.rand_mac_address()

        resp, port1 = self.create_port(node_id=node_id, address=address1)
        self.assertEqual('201', resp['status'])

        resp, port2 = self.create_port(node_id=node_id, address=address2)
        self.assertEqual('201', resp['status'])
        port_id = port2['uuid']

        patch = [{'path': '/address',
                  'op': 'replace',
                  'value': address1}]
        self.assertRaises(exc.Conflict,
                          self.client.update_port, port_id, patch)
 def _create_subnets_and_port(self, kwargs1=None, kwargs2=None):
     kwargs1 = kwargs1 or {}
     kwargs2 = kwargs2 or {}
     subnet1 = self.create_subnet(self.network, **kwargs1)
     subnet2 = self.create_subnet(self.network, **kwargs2)
     port_mac = data_utils.rand_mac_address()
     port = self.create_port(self.network, mac_address=port_mac)
     return port, subnet1, subnet2
Example #21
0
 def _get_ips_from_subnet(self, **kwargs):
     subnet = self.create_subnet(self.network, **kwargs)
     port_mac = data_utils.rand_mac_address()
     port = self.create_port(self.network, mac_address=port_mac)
     real_ip = next(iter(port['fixed_ips']), None)['ip_address']
     eui_ip = data_utils.get_ipv6_addr_by_EUI64(subnet['cidr'],
                                                port_mac).format()
     return real_ip, eui_ip
Example #22
0
    def test_create_port_specifying_uuid(self):
        node_id = self.node["uuid"]
        address = data_utils.rand_mac_address()
        uuid = data_utils.rand_uuid()

        _, port = self.create_port(node_id=node_id, address=address, uuid=uuid)

        _, body = self.client.show_port(uuid)
        self._assertExpected(port, body)
Example #23
0
    def test_update_port(self):
        node_id = self.node['uuid']
        port_id = self.create_port(node_id=node_id)['port']['uuid']

        new_address = data_utils.rand_mac_address()
        self.client.update_port(port_id, address=new_address)

        resp, body = self.client.show_port(port_id)
        self.assertEqual(body['address'], new_address)
    def test_create_port(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()

        _, port = self.create_port(node_id=node_id, address=address)

        _, body = self.client.show_port(port['uuid'])

        self._assertExpected(port, body)
Example #25
0
    def test_create_port_with_extra(self):
        node_id = self.node["uuid"]
        address = data_utils.rand_mac_address()
        extra = {"str": "value", "int": 123, "float": 0.123, "bool": True, "list": [1, 2, 3], "dict": {"foo": "bar"}}

        _, port = self.create_port(node_id=node_id, address=address, extra=extra)

        _, body = self.client.show_port(port["uuid"])
        self._assertExpected(port, body)
    def test_create_port_with_extra(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()
        extra = {'key': 'value'}

        _, port = self.create_port(node_id=node_id, address=address,
                                   extra=extra)

        _, body = self.client.show_port(port['uuid'])
        self._assertExpected(port, body)
Example #27
0
    def test_delete_port(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()
        port_id = self.create_port(node_id=node_id, address=address)['port'][
            'uuid']

        resp = self.delete_port(port_id)

        self.assertEqual(204, resp.status)
        self.assertRaises(exc.NotFound, self.client.show_port, port_id)
    def test_update_port_remove_nonexistent_property(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()

        resp, port = self.create_port(node_id=node_id, address=address)
        self.assertEqual('201', resp['status'])
        port_id = port['uuid']

        self.assertRaises(exc.BadRequest, self.client.update_port, port_id,
                          [{'path': '/nonexistent', 'op': 'remove'}])
    def test_update_port_add_malformed_extra(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()

        _, port = self.create_port(node_id=node_id, address=address)
        port_id = port['uuid']

        self.assertRaises(exc.BadRequest, self.client.update_port, port_id,
                          [{'path': '/extra/key', ' op': 'add',
                            'value': 0.123}])
    def test_update_port_add_nonexistent_property(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()

        _, port = self.create_port(node_id=node_id, address=address)
        port_id = port['uuid']

        self.assertRaises(exc.BadRequest, self.client.update_port, port_id,
                          [{'path': '/nonexistent', ' op': 'add',
                            'value': 'value'}])
Example #31
0
    def test_show_port(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()
        extra = {'key': 'value'}

        port_id = self.create_port(node_id=node_id,
                                   address=address,
                                   extra=extra)['port']['uuid']

        resp, port = self.client.show_port(port_id)

        self.assertEqual(200, resp.status)
        self.assertEqual(port_id, port['uuid'])
        self.assertEqual(address, port['address'])
        self.assertEqual(extra, port['extra'])
Example #32
0
    def test_update_port_replace_extra_item_with_malformed(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()
        extra = {'key': 'value'}

        resp, port = self.create_port(node_id=node_id, address=address,
                                      extra=extra)
        self.assertEqual('201', resp['status'])
        port_id = port['uuid']

        patch = [{'path': '/extra/key',
                  'op': 'replace',
                  'value': 0.123}]
        self.assertRaises(exc.BadRequest,
                          self.client.update_port, port_id, patch)
Example #33
0
    def test_update_port_mixed_ops_integrity(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()
        extra = {'key1': 'value1', 'key2': 'value2'}

        resp, port = self.create_port(node_id=node_id, address=address,
                                      extra=extra)
        self.assertEqual('201', resp['status'])
        port_id = port['uuid']

        new_address = data_utils.rand_mac_address()
        new_extra = {'key1': 'new-value1', 'key3': 'new-value3'}

        patch = [{'path': '/address',
                  'op': 'replace',
                  'value': new_address},
                 {'path': '/extra/key1',
                  'op': 'replace',
                  'value': new_extra['key1']},
                 {'path': '/extra/key2',
                  'op': 'remove'},
                 {'path': '/extra/key3',
                  'op': 'add',
                  'value': new_extra['key3']},
                 {'path': '/nonexistent',
                  'op': 'replace',
                  'value': 'value'}]

        self.assertRaises(exc.BadRequest, self.client.update_port, port_id,
                          patch)

        # patch should not be applied
        resp, body = self.client.show_port(port_id)
        self.assertEqual(200, resp.status)
        self.assertEqual(address, body['address'])
        self.assertEqual(extra, body['extra'])
    def test_update_port_replace_node_id_with_nonexistent(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()

        resp, port = self.create_port(node_id=node_id, address=address)
        self.assertEqual('201', resp['status'])
        port_id = port['uuid']

        patch = [{
            'path': '/node_uuid',
            'op': 'replace',
            'value': data_utils.rand_uuid()
        }]
        self.assertRaises(exc.BadRequest, self.client.update_port, port_id,
                          patch)
Example #35
0
    def test_update_port_replace_mac_with_malformed(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()

        _, port = self.create_port(node_id=node_id, address=address)
        port_id = port['uuid']

        patch = [{
            'path': '/address',
            'op': 'replace',
            'value': 'malformed:mac'
        }]

        self.assertRaises(lib_exc.BadRequest, self.client.update_port, port_id,
                          patch)
Example #36
0
    def test_update_port_replace_whole_extra_with_malformed(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()

        _, port = self.create_port(node_id=node_id, address=address)
        port_id = port['uuid']

        patch = [{
            'path': '/extra',
            'op': 'replace',
            'value': [1, 2, 3, 4, 'a']
        }]

        self.assertRaises(exc.BadRequest, self.client.update_port, port_id,
                          patch)
Example #37
0
    def test_create_port(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()

        result = self.create_port(node_id=node_id, address=address)

        port = result['port']

        resp, body = self.client.show_port(port['uuid'])

        self.assertEqual(200, resp.status)
        self.assertEqual(port['uuid'], body['uuid'])
        self.assertEqual(address, body['address'])
        self.assertEqual({}, body['extra'])
        self.assertEqual(node_id, body['node_uuid'])
Example #38
0
    def test_update_port_nonexistent(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()
        extra = {'key': 'value'}

        _, port = self.create_port(node_id=node_id,
                                   address=address,
                                   extra=extra)
        port_id = port['uuid']

        _, body = self.client.delete_port(port_id)

        patch = [{'path': '/extra/key', 'op': 'replace', 'value': 'new-value'}]
        self.assertRaises(lib_exc.NotFound, self.client.update_port, port_id,
                          patch)
Example #39
0
 def test_dhcpv6_two_subnets(self):
     """When one IPv6 subnet configured with dnsmasq SLAAC or DHCP stateless
     and other IPv6 is with DHCP stateful, port shall receive EUI-64 IP
     addresses from first subnet and DHCP address from second one.
     Order of subnet creating should be unimportant.
     """
     for order in ("slaac_first", "dhcp_first"):
         for ra_mode, add_mode in (
                 ('slaac', 'slaac'),
                 ('dhcpv6-stateless', 'dhcpv6-stateless'),
         ):
             kwargs = {'ipv6_ra_mode': ra_mode,
                       'ipv6_address_mode': add_mode}
             kwargs_dhcp = {'ipv6_address_mode': 'dhcpv6-stateful'}
             if order == "slaac_first":
                 subnet_slaac = self.create_subnet(self.network, **kwargs)
                 subnet_dhcp = self.create_subnet(
                     self.network, **kwargs_dhcp)
             else:
                 subnet_dhcp = self.create_subnet(
                     self.network, **kwargs_dhcp)
                 subnet_slaac = self.create_subnet(self.network, **kwargs)
             port_mac = data_utils.rand_mac_address()
             eui_ip = data_utils.get_ipv6_addr_by_EUI64(
                 subnet_slaac['cidr'],
                 port_mac
             ).format()
             port = self.create_port(self.network, mac_address=port_mac)
             real_ips = dict([(k['subnet_id'], k['ip_address'])
                              for k in port['fixed_ips']])
             real_dhcp_ip, real_eui_ip = [real_ips[sub['id']]
                                          for sub in [subnet_dhcp,
                                          subnet_slaac]]
             self.client.delete_port(port['id'])
             self.ports.pop()
             body = self.client.list_ports()
             ports_id_list = [i['id'] for i in body['ports']]
             self.assertNotIn(port['id'], ports_id_list)
             self._clean_network()
             self.assertEqual(real_eui_ip,
                              eui_ip,
                              'Real IP is {0}, but shall be {1}'.format(
                                  real_eui_ip,
                                  eui_ip))
             msg = ('Real IP address is {0} and it is NOT on '
                    'subnet {1}'.format(real_dhcp_ip, subnet_dhcp['cidr']))
             self.assertIn(netaddr.IPAddress(real_dhcp_ip),
                           netaddr.IPNetwork(subnet_dhcp['cidr']), msg)
Example #40
0
 def test_dhcpv6_64_subnets(self):
     """When one IPv6 subnet configured with dnsmasq SLAAC or DHCP stateless
     and other IPv4 is with DHCP of IPv4, port shall receive EUI-64 IP
     addresses from first subnet and IPv4 DHCP address from second one.
     Order of subnet creating should be unimportant.
     """
     for order in ("slaac_first", "dhcp_first"):
         for ra_mode, add_mode in (
             ('slaac', 'slaac'),
             ('dhcpv6-stateless', 'dhcpv6-stateless'),
         ):
             kwargs = {
                 'ipv6_ra_mode': ra_mode,
                 'ipv6_address_mode': add_mode
             }
             if order == "slaac_first":
                 subnet_slaac = self.create_subnet(self.network, **kwargs)
                 subnet_dhcp = self.create_subnet(self.network,
                                                  ip_version=4)
             else:
                 subnet_dhcp = self.create_subnet(self.network,
                                                  ip_version=4)
                 subnet_slaac = self.create_subnet(self.network, **kwargs)
             port_mac = data_utils.rand_mac_address()
             dhcp_ip = subnet_dhcp["allocation_pools"][0]["start"]
             eui_ip = data_utils.get_ipv6_addr_by_EUI64(
                 subnet_slaac['cidr'], port_mac).format()
             # TODO(sergsh): remove this when 1219795 is fixed
             dhcp_ip = [dhcp_ip, (netaddr.IPAddress(dhcp_ip) + 1).format()]
             port = self.create_port(self.network, mac_address=port_mac)
             real_ips = dict([(k['subnet_id'], k['ip_address'])
                              for k in port['fixed_ips']])
             real_dhcp_ip, real_eui_ip = [
                 real_ips[sub['id']] for sub in subnet_dhcp, subnet_slaac
             ]
             self._clean_network()
             self.assertTrue({real_eui_ip,
                              real_dhcp_ip}.issubset([eui_ip] + dhcp_ip))
             self.assertEqual(
                 real_eui_ip, eui_ip,
                 'Real IP is {0}, but shall be {1}'.format(
                     real_eui_ip, eui_ip))
             self.assertIn(
                 real_dhcp_ip, dhcp_ip,
                 'Real IP is {0}, but shall be one from {1}'.format(
                     real_dhcp_ip, str(dhcp_ip)))
Example #41
0
    def test_create_port_with_extra(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()
        extra = {'key': 'value'}

        result = self.create_port(node_id=node_id,
                                  address=address,
                                  extra=extra)
        port = result['port']

        resp, body = self.client.show_port(port['uuid'])

        self.assertEqual(200, resp.status)
        self.assertEqual(port['uuid'], body['uuid'])
        self.assertEqual(address, body['address'])
        self.assertEqual(extra, body['extra'])
        self.assertEqual(node_id, body['node_uuid'])
Example #42
0
    def test_update_port_add(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()

        _, port = self.create_port(node_id=node_id, address=address)

        extra = {'key1': 'value1', 'key2': 'value2'}

        patch = [{'path': '/extra/key1',
                  'op': 'add',
                  'value': extra['key1']},
                 {'path': '/extra/key2',
                  'op': 'add',
                  'value': extra['key2']}]

        self.client.update_port(port['uuid'], patch)

        _, body = self.client.show_port(port['uuid'])
        self.assertEqual(extra, body['extra'])
Example #43
0
    def test_create_port_with_extra(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()
        extra = {
            'str': 'value',
            'int': 123,
            'float': 0.123,
            'bool': True,
            'list': [1, 2, 3],
            'dict': {
                'foo': 'bar'
            }
        }

        _, port = self.create_port(node_id=node_id,
                                   address=address,
                                   extra=extra)

        _, body = self.client.show_port(port['uuid'])
        self._assertExpected(port, body)
 def test_dhcpv6_64_subnets(self):
     # NOTE: When one IPv6 subnet configured with dnsmasq SLAAC or DHCP
     # stateless and other IPv4 is with DHCP of IPv4, port shall receive
     # EUI-64 IP addresses from first subnet and IPv4 DHCP address from
     # second one. Order of subnet creating should be unimportant.
     for order in ("slaac_first", "dhcp_first"):
         for ra_mode, add_mode in (
                 ('slaac', 'slaac'),
                 ('dhcpv6-stateless', 'dhcpv6-stateless'),
         ):
             kwargs = {'ipv6_ra_mode': ra_mode,
                       'ipv6_address_mode': add_mode}
             if order == "slaac_first":
                 subnet_slaac = self.create_subnet(self.network, **kwargs)
                 subnet_dhcp = self.create_subnet(
                     self.network, ip_version=4)
             else:
                 subnet_dhcp = self.create_subnet(
                     self.network, ip_version=4)
                 subnet_slaac = self.create_subnet(self.network, **kwargs)
             port_mac = data_utils.rand_mac_address()
             eui_ip = data_utils.get_ipv6_addr_by_EUI64(
                 subnet_slaac['cidr'],
                 port_mac
             ).format()
             port = self.create_port(self.network, mac_address=port_mac)
             real_ips = dict([(k['subnet_id'], k['ip_address'])
                              for k in port['fixed_ips']])
             real_dhcp_ip, real_eui_ip = [real_ips[sub['id']]
                                          for sub in [subnet_dhcp,
                                          subnet_slaac]]
             self._clean_network()
             self.assertEqual(real_eui_ip,
                              eui_ip,
                              'Real IP is {0}, but shall be {1}'.format(
                                  real_eui_ip,
                                  eui_ip))
             msg = ('Real IP address is {0} and it is NOT on '
                    'subnet {1}'.format(real_dhcp_ip, subnet_dhcp['cidr']))
             self.assertIn(netaddr.IPAddress(real_dhcp_ip),
                           netaddr.IPNetwork(subnet_dhcp['cidr']), msg)
Example #45
0
    def test_list_ports(self):
        node_id = self.node['uuid']

        uuids = [
            self.create_port(
                node_id=node_id,
                address=data_utils.rand_mac_address())['port']['uuid']
            for i in xrange(5)
        ]

        resp, body = self.client.list_ports()
        self.assertEqual(200, resp.status)
        loaded_uuids = [p['uuid'] for p in body['ports']]

        for uuid in uuids:
            self.assertIn(uuid, loaded_uuids)

        # Verify self links.
        for port in body['ports']:
            self.validate_self_link('ports', port['uuid'],
                                    port['links'][0]['href'])
Example #46
0
    def test_list_ports_details(self):
        node_id = self.node['uuid']

        uuids = [
            self.create_port(node_id=node_id,
                             address=data_utils.rand_mac_address())
            [1]['uuid'] for i in range(0, 5)]

        _, body = self.client.list_ports_detail()

        ports_dict = dict((port['uuid'], port) for port in body['ports']
                          if port['uuid'] in uuids)

        for uuid in uuids:
            self.assertIn(uuid, ports_dict)
            port = ports_dict[uuid]
            self.assertIn('extra', port)
            self.assertIn('node_uuid', port)
            # never expose the node_id
            self.assertNotIn('node_id', port)
            # Verify self link.
            self.validate_self_link('ports', port['uuid'],
                                    port['links'][0]['href'])
Example #47
0
 def test_create_port_malformed_node_id(self):
     address = data_utils.rand_mac_address()
     self.assertRaises(exc.BadRequest, self.create_port,
                       node_id='malformed:nodeid', address=address)
Example #48
0
    def test_create_port_no_mandatory_field_node_id(self):
        address = data_utils.rand_mac_address()

        self.assertRaises(exc.BadRequest, self.create_port, node_id=None,
                          address=address)
Example #49
0
 def test_show_port_by_mac_not_allowed(self):
     self.assertRaises(exc.BadRequest, self.client.show_port,
                       data_utils.rand_mac_address())
Example #50
0
 def test_create_port_nonexsistent_node_id(self):
     node_id = str(data_utils.rand_uuid())
     address = data_utils.rand_mac_address()
     self.assertRaises(exc.BadRequest, self.create_port, node_id=node_id,
                       address=address)
Example #51
0
    def test_delete_port_by_mac_not_allowed(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()

        self.create_port(node_id=node_id, address=address)
        self.assertRaises(exc.BadRequest, self.client.delete_port, address)
Example #52
0
 def test_node_port_list(self):
     _, port = self.create_port(self.node['uuid'],
                                data_utils.rand_mac_address())
     _, body = self.client.list_node_ports(self.node['uuid'])
     self.assertIn(port['uuid'], [p['uuid'] for p in body['ports']])