예제 #1
0
    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': 0.123, 'key3': {'cat': 'meow'}}

        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'])
예제 #2
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'}

        _, 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(lib_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'])
예제 #3
0
    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': 0.123, 'key3': {'cat': 'meow'}}

        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'])
예제 #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)
예제 #5
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)
예제 #6
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"])
예제 #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())

        _, body = self.client.list_ports_detail(address=address)
        self.assertEqual(1, len(body['ports']))
        self.assertEqual(address, body['ports'][0]['address'])
예제 #8
0
    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(lib_exc.BadRequest, self.client.update_port,
                          uuid='malformed:uuid',
                          patch=[{'path': '/address', 'op': 'replace',
                                  'value': new_address}])
예제 #9
0
    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()

        _, port1 = self.create_port(node_id=node_id, address=address1)

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

        patch = [{'path': '/address', 'op': 'replace', 'value': address1}]
        self.assertRaises(lib_exc.Conflict, self.client.update_port, port_id,
                          patch)
예제 #10
0
    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()

        _, port1 = self.create_port(node_id=node_id, address=address1)

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

        patch = [{'path': '/address',
                  'op': 'replace',
                  'value': address1}]
        self.assertRaises(lib_exc.Conflict,
                          self.client.update_port, port_id, patch)
예제 #11
0
    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(lib_exc.BadRequest,
                          self.client.update_port,
                          uuid='malformed:uuid',
                          patch=[{
                              'path': '/address',
                              'op': 'replace',
                              'value': new_address
                          }])
예제 #12
0
    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'])
예제 #13
0
    def test_create_port_malformed_port_uuid(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()
        uuid = 'malformed:uuid'

        self.assertRaises(lib_exc.BadRequest, self.create_port,
                          node_id=node_id, address=address, uuid=uuid)
예제 #14
0
    def test_create_port_no_mandatory_field_node_id(self):
        address = data_utils.rand_mac_address()

        self.assertRaises(lib_exc.BadRequest,
                          self.create_port,
                          node_id=None,
                          address=address)
예제 #15
0
 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(lib_exc.Conflict,
                       self.create_port, node_id=node_id,
                       address=address)
예제 #16
0
    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'])
예제 #17
0
    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())
예제 #18
0
 def test_create_port_nonexsistent_node_id(self):
     node_id = str(data_utils.rand_uuid())
     address = data_utils.rand_mac_address()
     self.assertRaises(lib_exc.BadRequest,
                       self.create_port,
                       node_id=node_id,
                       address=address)
예제 #19
0
    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())
예제 #20
0
 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(lib_exc.Conflict,
                       self.create_port,
                       node_id=node_id,
                       address=address)
 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
예제 #22
0
    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(lib_exc.NotFound, self.client.show_port, port["uuid"])
예제 #23
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
예제 #24
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)
예제 #25
0
    def test_update_port_remove_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(lib_exc.BadRequest, self.client.update_port, port_id,
                          [{'path': '/nonexistent', 'op': 'remove'}])
예제 #26
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)

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

        self._assertExpected(port, body)
예제 #27
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)
예제 #28
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)

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

        self._assertExpected(port, body)
예제 #29
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)
예제 #30
0
    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(lib_exc.NotFound, self.client.show_port,
                          port['uuid'])
예제 #31
0
    def test_create_port_malformed_port_uuid(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()
        uuid = 'malformed:uuid'

        self.assertRaises(lib_exc.BadRequest,
                          self.create_port,
                          node_id=node_id,
                          address=address,
                          uuid=uuid)
예제 #32
0
    def test_update_port_replace_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']

        patch = [{'path': '/nonexistent', ' op': 'replace', 'value': 'value'}]

        self.assertRaises(lib_exc.BadRequest, self.client.update_port, port_id,
                          patch)
예제 #33
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)
예제 #34
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)
예제 #35
0
    def test_update_port_by_mac_not_allowed(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()
        extra = {'key': 'value'}

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

        patch = [{'path': '/extra/key', 'op': 'replace', 'value': 'new-value'}]

        self.assertRaises(lib_exc.BadRequest, self.client.update_port, address,
                          patch)
예제 #36
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'}

        _, 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(lib_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'])
예제 #37
0
    def test_update_port_replace_node_id_with_nonexistent(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': '/node_uuid',
                  'op': 'replace',
                  'value': data_utils.rand_uuid()}]
        self.assertRaises(lib_exc.BadRequest,
                          self.client.update_port, port_id, patch)
예제 #38
0
    def test_update_port_remove_mandatory_field_port_uuid(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(lib_exc.BadRequest, self.client.update_port, port_id,
                          [{
                              'path': '/uuid',
                              'op': 'remove'
                          }])
예제 #39
0
 def test_dhcpv6_two_subnets(self):
     """When one IPv6 subnet configured with IPv6 SLAAC or DHCPv6 stateless
     and other IPv6 is with DHCPv6 stateful, port shall receive EUI-64 IP
     addresses from first subnet and DHCPv6 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()
             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.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))
             self.assertIn(
                 real_dhcp_ip, dhcp_ip,
                 'Real IP is {0}, but shall be one from {1}'.format(
                     real_dhcp_ip,
                     str(dhcp_ip)))
 def test_dhcpv6_two_subnets(self):
     """When one IPv6 subnet configured with IPv6 SLAAC or DHCPv6 stateless
     and other IPv6 is with DHCPv6 stateful, port shall receive EUI-64 IP
     addresses from first subnet and DHCPv6 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()
             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.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))
             self.assertIn(
                 real_dhcp_ip, dhcp_ip,
                 'Real IP is {0}, but shall be one from {1}'.format(
                     real_dhcp_ip,
                     str(dhcp_ip)))
예제 #41
0
    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": 0.123, "key3": {"cat": "meow"}}

        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"])
예제 #42
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)
 def test_dhcpv6_64_subnets(self):
     """When a Network contains two subnets, one being an IPv6 subnet
     configured with ipv6_ra_mode either as slaac or dhcpv6-stateless,
     and the other subnet being an IPv4 subnet, a port attached to the
     network shall receive IP addresses from the subnets as follows: An
     IPv6 address calculated using EUI-64 from the first subnet, and an
     IPv4 address from the second subnet. The ordering of the subnets
     that the port is associated with should not affect this behavior.
     """
     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)))
예제 #44
0
 def test_dhcpv6_64_subnets(self):
     """When a Network contains two subnets, one being an IPv6 subnet
     configured with ipv6_ra_mode either as slaac or dhcpv6-stateless,
     and the other subnet being an IPv4 subnet, a port attached to the
     network shall receive IP addresses from the subnets as follows: An
     IPv6 address calculated using EUI-64 from the first subnet, and an
     IPv4 address from the second subnet. The ordering of the subnets
     that the port is associated with should not affect this behavior.
     """
     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)))
예제 #45
0
    def test_update_port_by_mac_not_allowed(self):
        node_id = self.node['uuid']
        address = data_utils.rand_mac_address()
        extra = {'key': 'value'}

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

        patch = [{'path': '/extra/key',
                  'op': 'replace',
                  'value': 'new-value'}]

        self.assertRaises(lib_exc.BadRequest,
                          self.client.update_port, address,
                          patch)
예제 #46
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)
예제 #47
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)
예제 #48
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)
예제 #49
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)))
예제 #50
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)
예제 #51
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"])
예제 #52
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)))
예제 #53
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'])
예제 #54
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'])
예제 #55
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"])
예제 #56
0
    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"])
예제 #57
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'])
예제 #58
0
 def test_show_port_by_mac_not_allowed(self):
     self.assertRaises(lib_exc.BadRequest, self.client.show_port,
                       data_utils.rand_mac_address())
예제 #59
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(lib_exc.BadRequest, self.client.delete_port, address)