Exemplo n.º 1
0
 def test_portgroup_by_id_no_such_portgroup(self):
     node = object_utils.create_test_node(self.context, driver='fake')
     object_utils.create_test_portgroup(self.context, node_id=node.id)
     with task_manager.acquire(self.context, node.uuid) as task:
         portgroup_id = 'invalid-portgroup-id'
         res = network.get_portgroup_by_id(task, portgroup_id)
     self.assertIsNone(res)
Exemplo n.º 2
0
 def test_portgroup_by_id_no_such_portgroup(self):
     node = object_utils.create_test_node(self.context)
     object_utils.create_test_portgroup(self.context, node_id=node.id)
     with task_manager.acquire(self.context, node.uuid) as task:
         portgroup_id = 'invalid-portgroup-id'
         res = network.get_portgroup_by_id(task, portgroup_id)
     self.assertIsNone(res)
Exemplo n.º 3
0
 def test__bind_flat_ports_set_binding_host_id_portgroup(self, update_mock):
     internal_info = {'tenant_vif_port_id': 'foo'}
     utils.create_test_portgroup(self.context,
                                 node_id=self.node.id,
                                 internal_info=internal_info,
                                 uuid=uuidutils.generate_uuid())
     utils.create_test_port(self.context,
                            node_id=self.node.id,
                            address='52:54:00:cf:2d:33',
                            internal_info={'tenant_vif_port_id': 'bar'},
                            uuid=uuidutils.generate_uuid())
     exp_body1 = {
         'binding:host_id': self.node.uuid,
         'binding:vnic_type': neutron.VNIC_BAREMETAL,
         'mac_address': '52:54:00:cf:2d:33'
     }
     exp_body2 = {
         'binding:host_id': self.node.uuid,
         'binding:vnic_type': neutron.VNIC_BAREMETAL,
         'mac_address': '52:54:00:cf:2d:31'
     }
     with task_manager.acquire(self.context, self.node.id) as task:
         self.interface._bind_flat_ports(task)
     update_mock.assert_has_calls([
         mock.call(self.context, 'bar', exp_body1),
         mock.call(self.context, 'foo', exp_body2)
     ])
Exemplo n.º 4
0
 def test_add_provisioning_network_set_binding_host_id_portgroup(
         self, client_mock):
     upd_mock = mock.Mock()
     client_mock.return_value.update_port = upd_mock
     internal_info = {'tenant_vif_port_id': 'foo'}
     utils.create_test_portgroup(self.context,
                                 node_id=self.node.id,
                                 internal_info=internal_info,
                                 uuid=uuidutils.generate_uuid())
     utils.create_test_port(self.context,
                            node_id=self.node.id,
                            address='52:54:00:cf:2d:33',
                            extra={'vif_port_id': 'bar'},
                            uuid=uuidutils.generate_uuid())
     exp_body = {
         'port': {
             'binding:host_id': self.node.uuid,
             'binding:vnic_type': neutron.VNIC_BAREMETAL
         }
     }
     with task_manager.acquire(self.context, self.node.id) as task:
         self.interface.add_provisioning_network(task)
     upd_mock.assert_has_calls(
         [mock.call('bar', exp_body),
          mock.call('foo', exp_body)])
Exemplo n.º 5
0
 def test_portgroup_by_id(self):
     node = object_utils.create_test_node(self.context, driver='fake')
     portgroup = object_utils.create_test_portgroup(self.context,
                                                    node_id=node.id)
     object_utils.create_test_portgroup(self.context,
                                        node_id=node.id,
                                        uuid=uuidutils.generate_uuid(),
                                        address='00:11:22:33:44:55',
                                        name='pg2')
     with task_manager.acquire(self.context, node.uuid) as task:
         res = network.get_portgroup_by_id(task, portgroup.id)
     self.assertEqual(portgroup.id, res.id)
Exemplo n.º 6
0
 def test_portgroup_by_id(self):
     node = object_utils.create_test_node(self.context)
     portgroup = object_utils.create_test_portgroup(self.context,
                                                    node_id=node.id)
     object_utils.create_test_portgroup(self.context,
                                        node_id=node.id,
                                        uuid=uuidutils.generate_uuid(),
                                        address='00:11:22:33:44:55',
                                        name='pg2')
     with task_manager.acquire(self.context, node.uuid) as task:
         res = network.get_portgroup_by_id(task, portgroup.id)
     self.assertEqual(portgroup.id, res.id)
Exemplo n.º 7
0
    def test_get_ip_addresses_for_port_and_portgroup(self, get_ip_mock):
        object_utils.create_test_portgroup(
            self.context, node_id=self.node.id, address='aa:bb:cc:dd:ee:ff',
            uuid=uuidutils.generate_uuid(),
            internal_info={'tenant_vif_port_id': 'test-vif-A'})

        with task_manager.acquire(self.context, self.node.uuid) as task:
            api = dhcp_factory.DHCPFactory().provider
            api.get_ip_addresses(task)
            get_ip_mock.assert_has_calls(
                [mock.call(task, task.ports[0], mock.ANY),
                 mock.call(task, task.portgroups[0], mock.ANY)])
Exemplo n.º 8
0
 def test_get_ip_addresses_for_port_and_portgroup(self, get_ip_mock):
     object_utils.create_test_portgroup(self.context,
                                        node_id=self.node.id,
                                        address='aa:bb:cc:dd:ee:ff',
                                        uuid=uuidutils.generate_uuid(),
                                        extra={'vif_port_id':
                                               'test-vif-A'})
     with task_manager.acquire(self.context, self.node.uuid) as task:
         api = dhcp_factory.DHCPFactory().provider
         api.get_ip_addresses(task)
         get_ip_mock.assert_has_calls(
             [mock.call(task, task.ports[0], mock.ANY),
              mock.call(task, task.portgroups[0], mock.ANY)])
Exemplo n.º 9
0
 def _objects_setup(self):
     pg1 = obj_utils.create_test_portgroup(self.context,
                                           node_id=self.node.id)
     pg1_ports = []
     # This portgroup contains 2 ports, both of them without VIF
     for i in range(2):
         pg1_ports.append(
             obj_utils.create_test_port(self.context,
                                        node_id=self.node.id,
                                        address='52:54:00:cf:2d:0%d' % i,
                                        uuid=uuidutils.generate_uuid(),
                                        portgroup_id=pg1.id))
     pg2 = obj_utils.create_test_portgroup(self.context,
                                           node_id=self.node.id,
                                           address='00:54:00:cf:2d:04',
                                           name='foo2',
                                           uuid=uuidutils.generate_uuid())
     pg2_ports = []
     # This portgroup contains 3 ports, one of them with 'some-vif'
     # attached, so the two free ones should be considered standalone
     for i in range(2, 4):
         pg2_ports.append(
             obj_utils.create_test_port(self.context,
                                        node_id=self.node.id,
                                        address='52:54:00:cf:2d:0%d' % i,
                                        uuid=uuidutils.generate_uuid(),
                                        portgroup_id=pg2.id))
     pg2_ports.append(
         obj_utils.create_test_port(self.context,
                                    node_id=self.node.id,
                                    address='52:54:00:cf:2d:04',
                                    extra={'vif_port_id': 'some-vif'},
                                    uuid=uuidutils.generate_uuid(),
                                    portgroup_id=pg2.id))
     # This portgroup has 'some-vif-2' attached to it and contains one port,
     # so neither portgroup nor port can be considered free
     pg3 = obj_utils.create_test_portgroup(
         self.context,
         node_id=self.node.id,
         address='00:54:00:cf:2d:05',
         name='foo3',
         uuid=uuidutils.generate_uuid(),
         internal_info={common.TENANT_VIF_KEY: 'some-vif-2'})
     pg3_ports = [
         obj_utils.create_test_port(self.context,
                                    node_id=self.node.id,
                                    address='52:54:00:cf:2d:05',
                                    uuid=uuidutils.generate_uuid(),
                                    portgroup_id=pg3.id)
     ]
     return pg1, pg1_ports, pg2, pg2_ports, pg3, pg3_ports
Exemplo n.º 10
0
 def test__unbind_flat_ports_portgroup(self, unbind_neutron_port_mock):
     internal_info = {'tenant_vif_port_id': 'foo'}
     utils.create_test_portgroup(self.context, node_id=self.node.id,
                                 internal_info=internal_info,
                                 uuid=uuidutils.generate_uuid())
     extra = {'vif_port_id': 'bar'}
     utils.create_test_port(self.context, node_id=self.node.id,
                            address='52:54:00:cf:2d:33', extra=extra,
                            uuid=uuidutils.generate_uuid())
     with task_manager.acquire(self.context, self.node.id) as task:
         self.interface._unbind_flat_ports(task)
     unbind_neutron_port_mock.has_calls(
         [mock.call('foo', context=self.context),
          mock.call('bar', context=self.context)])
Exemplo n.º 11
0
 def test__unbind_flat_ports_portgroup(self, unbind_neutron_port_mock):
     internal_info = {'tenant_vif_port_id': 'foo'}
     utils.create_test_portgroup(self.context, node_id=self.node.id,
                                 internal_info=internal_info,
                                 uuid=uuidutils.generate_uuid())
     extra = {'vif_port_id': 'bar'}
     utils.create_test_port(self.context, node_id=self.node.id,
                            address='52:54:00:cf:2d:33', extra=extra,
                            uuid=uuidutils.generate_uuid())
     with task_manager.acquire(self.context, self.node.id) as task:
         self.interface._unbind_flat_ports(task)
     unbind_neutron_port_mock.has_calls(
         [mock.call('foo', context=self.context),
          mock.call('bar', context=self.context)])
Exemplo n.º 12
0
 def test_ports_by_portgroup_id_empty(self):
     node = object_utils.create_test_node(self.context, driver='fake')
     portgroup = object_utils.create_test_portgroup(self.context,
                                                    node_id=node.id)
     with task_manager.acquire(self.context, node.uuid) as task:
         res = network.get_ports_by_portgroup_id(task, portgroup.id)
     self.assertEqual([], res)
Exemplo n.º 13
0
 def test_configure_tenant_networks_with_portgroups(self, glgi_mock,
                                                    client_mock):
     pg = utils.create_test_portgroup(
         self.context,
         node_id=self.node.id,
         address='ff:54:00:cf:2d:32',
         extra={'vif_port_id': uuidutils.generate_uuid()})
     port1 = utils.create_test_port(self.context,
                                    node_id=self.node.id,
                                    address='ff:54:00:cf:2d:33',
                                    uuid=uuidutils.generate_uuid(),
                                    portgroup_id=pg.id,
                                    local_link_connection={
                                        'switch_id': '0a:1b:2c:3d:4e:ff',
                                        'port_id': 'Ethernet1/1',
                                        'switch_info': 'switch2'
                                    })
     port2 = utils.create_test_port(self.context,
                                    node_id=self.node.id,
                                    address='ff:54:00:cf:2d:34',
                                    uuid=uuidutils.generate_uuid(),
                                    portgroup_id=pg.id,
                                    local_link_connection={
                                        'switch_id': '0a:1b:2c:3d:4e:ff',
                                        'port_id': 'Ethernet1/2',
                                        'switch_info': 'switch2'
                                    })
     upd_mock = mock.Mock()
     client_mock.return_value.update_port = upd_mock
     local_group_info = {'a': 'b'}
     glgi_mock.return_value = local_group_info
     expected_body = {
         'port': {
             'binding:vnic_type': 'baremetal',
             'binding:host_id': self.node.uuid,
         }
     }
     call1_body = copy.deepcopy(expected_body)
     call1_body['port']['binding:profile'] = {
         'local_link_information': [self.port.local_link_connection],
     }
     call2_body = copy.deepcopy(expected_body)
     call2_body['port']['binding:profile'] = {
         'local_link_information':
         [port1.local_link_connection, port2.local_link_connection],
         'local_group_information':
         local_group_info
     }
     with task_manager.acquire(self.context, self.node.id) as task:
         # Override task.portgroups here, to have ability to check
         # that mocked get_local_group_information was called with
         # this portgroup object.
         task.portgroups = [pg]
         self.interface.configure_tenant_networks(task)
         client_mock.assert_called_once_with()
         glgi_mock.assert_called_once_with(task, pg)
     upd_mock.assert_has_calls([
         mock.call(self.port.extra['vif_port_id'], call1_body),
         mock.call(pg.extra['vif_port_id'], call2_body)
     ])
Exemplo n.º 14
0
 def test_ports_by_portgroup_id_empty(self):
     node = object_utils.create_test_node(self.context)
     portgroup = object_utils.create_test_portgroup(self.context,
                                                    node_id=node.id)
     with task_manager.acquire(self.context, node.uuid) as task:
         res = network.get_ports_by_portgroup_id(task, portgroup.id)
     self.assertEqual([], res)
Exemplo n.º 15
0
 def test_update_portgroup_remove_address(self, mac_update_mock):
     pg = obj_utils.create_test_portgroup(self.context,
                                          node_id=self.node.id,
                                          extra={'vif_port_id': 'fake-id'})
     pg.address = None
     with task_manager.acquire(self.context, self.node.id) as task:
         self.interface.portgroup_changed(task, pg)
     self.assertFalse(mac_update_mock.called)
Exemplo n.º 16
0
 def test_update_portgroup_vif(self, mac_update_mock, mock_warn):
     pg = obj_utils.create_test_portgroup(self.context,
                                          node_id=self.node.id)
     extra = {'vif_port_id': 'foo'}
     pg.extra = extra
     with task_manager.acquire(self.context, self.node.id) as task:
         self.interface.portgroup_changed(task, pg)
     self.assertFalse(mac_update_mock.called)
     self.assertEqual(1, mock_warn.call_count)
Exemplo n.º 17
0
 def test_update_portgroup_address(self, mac_update_mock):
     pg = obj_utils.create_test_portgroup(self.context,
                                          node_id=self.node.id,
                                          extra={'vif_port_id': 'fake-id'})
     new_address = '11:22:33:44:55:bb'
     pg.address = new_address
     with task_manager.acquire(self.context, self.node.id) as task:
         self.interface.portgroup_changed(task, pg)
     mac_update_mock.assert_called_once_with('fake-id', new_address)
Exemplo n.º 18
0
 def test_update_portgroup_address_no_vif(self, mac_update_mock):
     pg = obj_utils.create_test_portgroup(self.context,
                                          node_id=self.node.id)
     new_address = '11:22:33:44:55:bb'
     pg.address = new_address
     with task_manager.acquire(self.context, self.node.id) as task:
         self.interface.portgroup_changed(task, pg)
     self.assertEqual(new_address, pg.address)
     self.assertFalse(mac_update_mock.called)
Exemplo n.º 19
0
 def test_update_portgroup_vif_removal_no_deprecation(
         self, mac_update_mock, mock_warn):
     pg = obj_utils.create_test_portgroup(self.context,
                                          node_id=self.node.id,
                                          extra={'vif_port_id': 'foo'})
     pg.extra = {}
     with task_manager.acquire(self.context, self.node.id) as task:
         self.interface.portgroup_changed(task, pg)
     self.assertFalse(mac_update_mock.called)
     self.assertFalse(mock_warn.called)
Exemplo n.º 20
0
 def test_configure_tenant_networks_with_portgroups(
         self, glgi_mock, client_mock, wait_agent_mock):
     pg = utils.create_test_portgroup(
         self.context, node_id=self.node.id, address='ff:54:00:cf:2d:32',
         extra={'vif_port_id': uuidutils.generate_uuid()})
     port1 = utils.create_test_port(
         self.context, node_id=self.node.id, address='ff:54:00:cf:2d:33',
         uuid=uuidutils.generate_uuid(),
         portgroup_id=pg.id,
         local_link_connection={'switch_id': '0a:1b:2c:3d:4e:ff',
                                'port_id': 'Ethernet1/1',
                                'switch_info': 'switch2'}
     )
     port2 = utils.create_test_port(
         self.context, node_id=self.node.id, address='ff:54:00:cf:2d:34',
         uuid=uuidutils.generate_uuid(),
         portgroup_id=pg.id,
         local_link_connection={'switch_id': '0a:1b:2c:3d:4e:ff',
                                'port_id': 'Ethernet1/2',
                                'switch_info': 'switch2'}
     )
     upd_mock = mock.Mock()
     client_mock.return_value.update_port = upd_mock
     local_group_info = {'a': 'b'}
     glgi_mock.return_value = local_group_info
     expected_body = {
         'port': {
             'binding:vnic_type': 'baremetal',
             'binding:host_id': self.node.uuid,
         }
     }
     call1_body = copy.deepcopy(expected_body)
     call1_body['port']['binding:profile'] = {
         'local_link_information': [self.port.local_link_connection],
     }
     call1_body['port']['mac_address'] = '52:54:00:cf:2d:32'
     call2_body = copy.deepcopy(expected_body)
     call2_body['port']['binding:profile'] = {
         'local_link_information': [port1.local_link_connection,
                                    port2.local_link_connection],
         'local_group_information': local_group_info
     }
     call2_body['port']['mac_address'] = 'ff:54:00:cf:2d:32'
     with task_manager.acquire(self.context, self.node.id) as task:
         # Override task.portgroups here, to have ability to check
         # that mocked get_local_group_information was called with
         # this portgroup object.
         task.portgroups = [pg]
         self.interface.configure_tenant_networks(task)
         client_mock.assert_called_once_with(context=task.context)
         glgi_mock.assert_called_once_with(task, pg)
     upd_mock.assert_has_calls(
         [mock.call(self.port.extra['vif_port_id'], call1_body),
          mock.call(pg.extra['vif_port_id'], call2_body)]
     )
Exemplo n.º 21
0
 def test_get_free_port_like_object_portgroup_first(self, vpi_mock):
     pg = obj_utils.create_test_portgroup(self.context,
                                          node_id=self.node.id)
     obj_utils.create_test_port(self.context,
                                node_id=self.node.id,
                                address='52:54:00:cf:2d:01',
                                uuid=uuidutils.generate_uuid(),
                                portgroup_id=pg.id)
     with task_manager.acquire(self.context, self.node.id) as task:
         res = common.get_free_port_like_object(task, self.vif_id)
         self.assertEqual(pg.uuid, res.uuid)
Exemplo n.º 22
0
 def test_configure_tenant_networks_with_portgroups(self, client_mock):
     pg = utils.create_test_portgroup(
         self.context,
         node_id=self.node.id,
         address="ff:54:00:cf:2d:32",
         extra={"vif_port_id": uuidutils.generate_uuid()},
     )
     port1 = utils.create_test_port(
         self.context,
         node_id=self.node.id,
         address="ff:54:00:cf:2d:33",
         uuid=uuidutils.generate_uuid(),
         portgroup_id=pg.id,
         local_link_connection={
             "switch_id": "0a:1b:2c:3d:4e:ff",
             "port_id": "Ethernet1/1",
             "switch_info": "switch2",
         },
     )
     port2 = utils.create_test_port(
         self.context,
         node_id=self.node.id,
         address="ff:54:00:cf:2d:34",
         uuid=uuidutils.generate_uuid(),
         portgroup_id=pg.id,
         local_link_connection={
             "switch_id": "0a:1b:2c:3d:4e:ff",
             "port_id": "Ethernet1/2",
             "switch_info": "switch2",
         },
     )
     upd_mock = mock.Mock()
     client_mock.return_value.update_port = upd_mock
     expected_body = {
         "port": {
             "device_owner": "baremetal:none",
             "device_id": self.node.uuid,
             "admin_state_up": True,
             "binding:vnic_type": "baremetal",
             "binding:host_id": self.node.uuid,
         }
     }
     call1_body = copy.deepcopy(expected_body)
     call1_body["port"]["binding:profile"] = {"local_link_information": [self.port.local_link_connection]}
     call2_body = copy.deepcopy(expected_body)
     call2_body["port"]["binding:profile"] = {
         "local_link_information": [port1.local_link_connection, port2.local_link_connection]
     }
     with task_manager.acquire(self.context, self.node.id) as task:
         self.interface.configure_tenant_networks(task)
         client_mock.assert_called_once_with(task.context.auth_token)
     upd_mock.assert_has_calls(
         [mock.call(self.port.extra["vif_port_id"], call1_body), mock.call(pg.extra["vif_port_id"], call2_body)]
     )
Exemplo n.º 23
0
 def test__bind_flat_ports_set_binding_host_id_portgroup(self, client_mock):
     upd_mock = mock.Mock()
     client_mock.return_value.update_port = upd_mock
     internal_info = {'tenant_vif_port_id': 'foo'}
     utils.create_test_portgroup(
         self.context, node_id=self.node.id, internal_info=internal_info,
         uuid=uuidutils.generate_uuid())
     utils.create_test_port(
         self.context, node_id=self.node.id, address='52:54:00:cf:2d:33',
         extra={'vif_port_id': 'bar'}, uuid=uuidutils.generate_uuid())
     exp_body1 = {'port': {'binding:host_id': self.node.uuid,
                           'binding:vnic_type': neutron.VNIC_BAREMETAL,
                           'mac_address': '52:54:00:cf:2d:33'}}
     exp_body2 = {'port': {'binding:host_id': self.node.uuid,
                           'binding:vnic_type': neutron.VNIC_BAREMETAL,
                           'mac_address': '52:54:00:cf:2d:31'}}
     with task_manager.acquire(self.context, self.node.id) as task:
         self.interface._bind_flat_ports(task)
     upd_mock.assert_has_calls([
         mock.call('bar', exp_body1), mock.call('foo', exp_body2)])
Exemplo n.º 24
0
 def test_unconfigure_tenant_networks_portgroup_2(self, mock_unbind_port):
     pg = utils.create_test_portgroup(
         self.context, node_id=self.node.id, address=None,
         internal_info={'tenant_vif_port_id': uuidutils.generate_uuid()})
     with task_manager.acquire(self.context, self.node.id) as task:
         self.interface.unconfigure_tenant_networks(task)
         mock_unbind_port.assert_has_calls([
             mock.call(self.port.internal_info['tenant_vif_port_id'],
                       context=task.context,
                       reset_mac=True),
             mock.call(pg.internal_info['tenant_vif_port_id'],
                       context=task.context, reset_mac=False)])
Exemplo n.º 25
0
 def test_update_portgroup_address_fail(self, mac_update_mock):
     pg = obj_utils.create_test_portgroup(self.context,
                                          node_id=self.node.id,
                                          extra={'vif_port_id': 'fake-id'})
     new_address = '11:22:33:44:55:bb'
     pg.address = new_address
     mac_update_mock.side_effect = (
         exception.FailedToUpdateMacOnPort('boom'))
     with task_manager.acquire(self.context, self.node.id) as task:
         self.assertRaises(exception.FailedToUpdateMacOnPort,
                           self.interface.portgroup_changed, task, pg)
     mac_update_mock.assert_called_once_with('fake-id', new_address)
Exemplo n.º 26
0
 def test_add_provisioning_network_set_binding_host_id_portgroup(
         self, client_mock):
     upd_mock = mock.Mock()
     client_mock.return_value.update_port = upd_mock
     instance_info = self.node.instance_info
     instance_info['nova_host_id'] = 'nova_host_id'
     self.node.instance_info = instance_info
     self.node.save()
     internal_info = {'tenant_vif_port_id': 'foo'}
     utils.create_test_portgroup(
         self.context, node_id=self.node.id, internal_info=internal_info,
         uuid=uuidutils.generate_uuid())
     utils.create_test_port(
         self.context, node_id=self.node.id, address='52:54:00:cf:2d:33',
         extra={'vif_port_id': 'bar'}, uuid=uuidutils.generate_uuid())
     exp_body = {'port': {'binding:host_id': 'nova_host_id'}}
     with task_manager.acquire(self.context, self.node.id) as task:
         self.interface.add_provisioning_network(task)
     upd_mock.assert_has_calls([
         mock.call('bar', exp_body), mock.call('foo', exp_body)
     ])
Exemplo n.º 27
0
 def test_configure_tenant_networks_with_portgroups_no_address(
         self, glgi_mock, client_mock, update_mock, wait_agent_mock,
         port_data_mock):
     pg = utils.create_test_portgroup(
         self.context, node_id=self.node.id, address=None,
         internal_info={'tenant_vif_port_id': uuidutils.generate_uuid()})
     port1 = utils.create_test_port(
         self.context, node_id=self.node.id, address='ff:54:00:cf:2d:33',
         uuid=uuidutils.generate_uuid(),
         portgroup_id=pg.id,
         local_link_connection={'switch_id': '0a:1b:2c:3d:4e:ff',
                                'port_id': 'Ethernet1/1',
                                'switch_info': 'switch2'}
     )
     port2 = utils.create_test_port(
         self.context, node_id=self.node.id, address='ff:54:00:cf:2d:34',
         uuid=uuidutils.generate_uuid(),
         portgroup_id=pg.id,
         local_link_connection={'switch_id': '0a:1b:2c:3d:4e:ff',
                                'port_id': 'Ethernet1/2',
                                'switch_info': 'switch2'}
     )
     local_group_info = {'a': 'b'}
     glgi_mock.return_value = local_group_info
     expected_attrs = {'binding:vnic_type': 'baremetal',
                       'binding:host_id': self.node.uuid}
     call1_attrs = copy.deepcopy(expected_attrs)
     call1_attrs['binding:profile'] = {
         'local_link_information': [self.port.local_link_connection]
     }
     call1_attrs['mac_address'] = '52:54:00:cf:2d:32'
     call2_attrs = copy.deepcopy(expected_attrs)
     call2_attrs['binding:profile'] = {
         'local_link_information': [port1.local_link_connection,
                                    port2.local_link_connection],
         'local_group_information': local_group_info
     }
     with task_manager.acquire(self.context, self.node.id) as task:
         # Override task.portgroups here, to have ability to check
         # that mocked get_local_group_information was called with
         # this portgroup object.
         task.portgroups = [pg]
         self.interface.configure_tenant_networks(task)
         client_mock.assert_called_once_with(context=task.context)
         glgi_mock.assert_called_once_with(task, pg)
     update_mock.assert_has_calls(
         [mock.call(self.context,
                    self.port.internal_info['tenant_vif_port_id'],
                    call1_attrs),
          mock.call(self.context,
                    pg.internal_info['tenant_vif_port_id'],
                    call2_attrs)]
     )
Exemplo n.º 28
0
 def test_update_portgroup_extra_new_key(self, mac_update_mock, mock_warn):
     pg = obj_utils.create_test_portgroup(self.context,
                                          node_id=self.node.id,
                                          extra={'vif_port_id': 'vif-id'})
     expected_extra = pg.extra
     expected_extra['foo'] = 'bar'
     pg.extra = expected_extra
     with task_manager.acquire(self.context, self.node.id) as task:
         self.interface.portgroup_changed(task, pg)
     self.assertFalse(mac_update_mock.called)
     self.assertFalse(mock_warn.called)
     self.assertEqual(expected_extra, pg.extra)
Exemplo n.º 29
0
 def test_ports_by_portgroup_id(self):
     node = object_utils.create_test_node(self.context)
     portgroup = object_utils.create_test_portgroup(self.context,
                                                    node_id=node.id)
     port = object_utils.create_test_port(self.context, node_id=node.id,
                                          portgroup_id=portgroup.id)
     object_utils.create_test_port(self.context, node_id=node.id,
                                   uuid=uuidutils.generate_uuid(),
                                   address='00:11:22:33:44:55')
     with task_manager.acquire(self.context, node.uuid) as task:
         res = network.get_ports_by_portgroup_id(task, portgroup.id)
     self.assertEqual([port.id], [p.id for p in res])
Exemplo n.º 30
0
 def test_configure_tenant_networks_with_portgroups(self, client_mock):
     pg = utils.create_test_portgroup(
         self.context,
         node_id=self.node.id,
         address='ff:54:00:cf:2d:32',
         extra={'vif_port_id': uuidutils.generate_uuid()})
     port1 = utils.create_test_port(self.context,
                                    node_id=self.node.id,
                                    address='ff:54:00:cf:2d:33',
                                    uuid=uuidutils.generate_uuid(),
                                    portgroup_id=pg.id,
                                    local_link_connection={
                                        'switch_id': '0a:1b:2c:3d:4e:ff',
                                        'port_id': 'Ethernet1/1',
                                        'switch_info': 'switch2'
                                    })
     port2 = utils.create_test_port(self.context,
                                    node_id=self.node.id,
                                    address='ff:54:00:cf:2d:34',
                                    uuid=uuidutils.generate_uuid(),
                                    portgroup_id=pg.id,
                                    local_link_connection={
                                        'switch_id': '0a:1b:2c:3d:4e:ff',
                                        'port_id': 'Ethernet1/2',
                                        'switch_info': 'switch2'
                                    })
     upd_mock = mock.Mock()
     client_mock.return_value.update_port = upd_mock
     expected_body = {
         'port': {
             'device_owner': 'baremetal:none',
             'device_id': self.node.uuid,
             'admin_state_up': True,
             'binding:vnic_type': 'baremetal',
             'binding:host_id': self.node.uuid,
         }
     }
     call1_body = copy.deepcopy(expected_body)
     call1_body['port']['binding:profile'] = {
         'local_link_information': [self.port.local_link_connection]
     }
     call2_body = copy.deepcopy(expected_body)
     call2_body['port']['binding:profile'] = {
         'local_link_information':
         [port1.local_link_connection, port2.local_link_connection]
     }
     with task_manager.acquire(self.context, self.node.id) as task:
         self.interface.configure_tenant_networks(task)
         client_mock.assert_called_once_with(task.context.auth_token)
     upd_mock.assert_has_calls([
         mock.call(self.port.extra['vif_port_id'], call1_body),
         mock.call(pg.extra['vif_port_id'], call2_body)
     ])
Exemplo n.º 31
0
 def test__get_ip_addresses_portgroup_int_info(self, mock_gfia):
     kwargs1 = {'internal_info': {'tenant_vif_port_id': 'test-vif-A'}}
     ip_address = '10.10.0.1'
     expected = [ip_address]
     pg = object_utils.create_test_portgroup(
         self.context, node_id=self.node.id,
         address='aa:bb:cc:dd:ee:ff', uuid=uuidutils.generate_uuid(),
         **kwargs1)
     mock_gfia.return_value = ip_address
     with task_manager.acquire(self.context, self.node.uuid) as task:
         api = dhcp_factory.DHCPFactory().provider
         result = api._get_ip_addresses(task, [pg], mock.sentinel.client)
     self.assertEqual(expected, result)
Exemplo n.º 32
0
 def test__get_port_ip_address_for_portgroup_with_exception(
         self, mock_gfia):
     expected = "192.168.1.3"
     pg = object_utils.create_test_portgroup(self.context,
                                             node_id=self.node.id,
                                             address='aa:bb:cc:dd:ee:ff',
                                             uuid=uuidutils.generate_uuid())
     mock_gfia.return_value = expected
     with task_manager.acquire(self.context, self.node.uuid) as task:
         api = dhcp_factory.DHCPFactory().provider
         self.assertRaises(exception.FailedToGetIPAddressOnPort,
                           api._get_port_ip_address, task, pg,
                           mock.sentinel.client)
Exemplo n.º 33
0
 def test__get_port_ip_address_for_portgroup(self, mock_gfia):
     expected = "192.168.1.3"
     pg = object_utils.create_test_portgroup(
         self.context,
         node_id=self.node.id,
         address='aa:bb:cc:dd:ee:ff',
         uuid=uuidutils.generate_uuid(),
         extra={'vif_port_id': 'test-vif-A'})
     mock_gfia.return_value = expected
     with task_manager.acquire(self.context, self.node.uuid) as task:
         api = dhcp_factory.DHCPFactory().provider
         result = api._get_port_ip_address(task, pg, mock.sentinel.client)
     self.assertEqual(expected, result)
     mock_gfia.assert_called_once_with('test-vif-A', mock.sentinel.client)
Exemplo n.º 34
0
 def test__get_port_ip_address_for_portgroup_with_exception(
         self, mock_gfia):
     expected = "192.168.1.3"
     pg = object_utils.create_test_portgroup(self.context,
                                             node_id=self.node.id,
                                             address='aa:bb:cc:dd:ee:ff',
                                             uuid=uuidutils.generate_uuid())
     mock_gfia.return_value = expected
     with task_manager.acquire(self.context,
                               self.node.uuid) as task:
         api = dhcp_factory.DHCPFactory().provider
         self.assertRaises(exception.FailedToGetIPAddressOnPort,
                           api._get_port_ip_address, task, pg,
                           mock.sentinel.client)
Exemplo n.º 35
0
 def test__get_ip_addresses_portgroup(self, mock_gfia):
     ip_address = '10.10.0.1'
     expected = [ip_address]
     pg = object_utils.create_test_portgroup(self.context,
                                             node_id=self.node.id,
                                             address='aa:bb:cc:dd:ee:ff',
                                             uuid=uuidutils.generate_uuid(),
                                             extra={'vif_port_id':
                                                    'test-vif-A'})
     mock_gfia.return_value = ip_address
     with task_manager.acquire(self.context, self.node.uuid) as task:
         api = dhcp_factory.DHCPFactory().provider
         result = api._get_ip_addresses(task, [pg], mock.sentinel.client)
     self.assertEqual(expected, result)
Exemplo n.º 36
0
 def test_vif_detach_in_extra_portgroup(self):
     vif_id = uuidutils.generate_uuid()
     pg = obj_utils.create_test_portgroup(self.context,
                                          node_id=self.node.id,
                                          extra={'vif_port_id': vif_id})
     obj_utils.create_test_port(self.context,
                                node_id=self.node.id,
                                address='52:54:00:cf:2d:01',
                                portgroup_id=pg.id,
                                uuid=uuidutils.generate_uuid())
     with task_manager.acquire(self.context, self.node.id) as task:
         self.interface.vif_detach(task, vif_id)
         pg.refresh()
         self.assertFalse('vif_port_id' in pg.extra)
         self.assertFalse(common.TENANT_VIF_KEY in pg.internal_info)
Exemplo n.º 37
0
 def test__get_port_ip_address_for_portgroup(self, mock_gfia):
     expected = "192.168.1.3"
     pg = object_utils.create_test_portgroup(
         self.context, node_id=self.node.id, address='aa:bb:cc:dd:ee:ff',
         uuid=uuidutils.generate_uuid(),
         internal_info={'tenant_vif_port_id': 'test-vif-A'})
     mock_gfia.return_value = expected
     with task_manager.acquire(self.context,
                               self.node.uuid) as task:
         api = dhcp_factory.DHCPFactory().provider
         result = api._get_port_ip_address(task, pg,
                                           mock.sentinel.client)
     self.assertEqual(expected, result)
     mock_gfia.assert_called_once_with(mock.ANY, 'test-vif-A',
                                       mock.sentinel.client)
Exemplo n.º 38
0
 def test_get_free_port_like_object_vif_attached_to_portgroup_extra(
         self, vpi_mock):
     pg = obj_utils.create_test_portgroup(
         self.context,
         node_id=self.node.id,
         extra={'vif_port_id': self.vif_id})
     obj_utils.create_test_port(self.context,
                                node_id=self.node.id,
                                address='52:54:00:cf:2d:01',
                                uuid=uuidutils.generate_uuid(),
                                portgroup_id=pg.id)
     with task_manager.acquire(self.context, self.node.id) as task:
         self.assertRaisesRegex(exception.VifAlreadyAttached,
                                r"already attached to Ironic Portgroup",
                                common.get_free_port_like_object, task,
                                self.vif_id)
Exemplo n.º 39
0
 def test_configure_tenant_networks_with_portgroups(self, client_mock):
     pg = utils.create_test_portgroup(
         self.context, node_id=self.node.id, address='ff:54:00:cf:2d:32',
         extra={'vif_port_id': uuidutils.generate_uuid()})
     port1 = utils.create_test_port(
         self.context, node_id=self.node.id, address='ff:54:00:cf:2d:33',
         uuid=uuidutils.generate_uuid(),
         portgroup_id=pg.id,
         local_link_connection={'switch_id': '0a:1b:2c:3d:4e:ff',
                                'port_id': 'Ethernet1/1',
                                'switch_info': 'switch2'}
     )
     port2 = utils.create_test_port(
         self.context, node_id=self.node.id, address='ff:54:00:cf:2d:34',
         uuid=uuidutils.generate_uuid(),
         portgroup_id=pg.id,
         local_link_connection={'switch_id': '0a:1b:2c:3d:4e:ff',
                                'port_id': 'Ethernet1/2',
                                'switch_info': 'switch2'}
     )
     upd_mock = mock.Mock()
     client_mock.return_value.update_port = upd_mock
     expected_body = {
         'port': {
             'device_owner': 'baremetal:none',
             'device_id': self.node.uuid,
             'admin_state_up': True,
             'binding:vnic_type': 'baremetal',
             'binding:host_id': self.node.uuid,
         }
     }
     call1_body = copy.deepcopy(expected_body)
     call1_body['port']['binding:profile'] = {
         'local_link_information': [self.port.local_link_connection]
     }
     call2_body = copy.deepcopy(expected_body)
     call2_body['port']['binding:profile'] = {
         'local_link_information': [port1.local_link_connection,
                                    port2.local_link_connection]
     }
     with task_manager.acquire(self.context, self.node.id) as task:
         self.interface.configure_tenant_networks(task)
         client_mock.assert_called_once_with(task.context.auth_token)
     upd_mock.assert_has_calls(
         [mock.call(self.port.extra['vif_port_id'], call1_body),
          mock.call(pg.extra['vif_port_id'], call2_body)]
     )
Exemplo n.º 40
0
    def test_port_changed_message_format_failure(self, dhcp_update_mock):
        pg = obj_utils.create_test_portgroup(self.context,
                                             node_id=self.node.id,
                                             standalone_ports_supported=False)

        port = obj_utils.create_test_port(self.context,
                                          node_id=self.node.id,
                                          uuid=uuidutils.generate_uuid(),
                                          address="aa:bb:cc:dd:ee:01",
                                          extra={'vif_port_id': 'blah'},
                                          pxe_enabled=False)
        port.portgroup_id = pg.id

        with task_manager.acquire(self.context, self.node.id) as task:
            self.assertRaisesRegex(exception.Conflict,
                                   "VIF blah is attached to the port",
                                   self.interface.port_changed, task, port)
Exemplo n.º 41
0
    def test_update_portgroup_nostandalone_ports_pxe_ports_exc(
            self, mac_update_mock):
        pg = obj_utils.create_test_portgroup(self.context,
                                             node_id=self.node.id)
        extra = {'vif_port_id': 'foo'}
        obj_utils.create_test_port(self.context,
                                   node_id=self.node.id,
                                   extra=extra,
                                   pxe_enabled=True,
                                   portgroup_id=pg.id,
                                   address="aa:bb:cc:dd:ee:01",
                                   uuid=uuidutils.generate_uuid())

        pg.standalone_ports_supported = False
        with task_manager.acquire(self.context, self.node.id) as task:
            self.assertRaisesRegex(exception.Conflict,
                                   "VIF foo is attached to this port",
                                   self.interface.portgroup_changed, task, pg)
Exemplo n.º 42
0
 def test_get_local_group_information(self):
     pg = object_utils.create_test_portgroup(
         self.context, node_id=self.node.id,
         uuid=uuidutils.generate_uuid(),
         address='52:54:55:cf:2d:32',
         mode='802.3ad', properties={'bond_opt1': 'foo',
                                     'opt2': 'bar'},
         name='test-pg'
     )
     expected = {
         'id': pg.uuid,
         'name': pg.name,
         'bond_mode': pg.mode,
         'bond_properties': {'bond_opt1': 'foo', 'bond_opt2': 'bar'},
     }
     with task_manager.acquire(self.context, self.node.uuid) as task:
         res = neutron.get_local_group_information(task, pg)
     self.assertEqual(expected, res)
Exemplo n.º 43
0
 def test_get_local_group_information(self):
     pg = object_utils.create_test_portgroup(
         self.context, node_id=self.node.id,
         uuid=uuidutils.generate_uuid(),
         address='52:54:55:cf:2d:32',
         mode='802.3ad', properties={'bond_opt1': 'foo',
                                     'opt2': 'bar'},
         name='test-pg'
     )
     expected = {
         'id': pg.uuid,
         'name': pg.name,
         'bond_mode': pg.mode,
         'bond_properties': {'bond_opt1': 'foo', 'bond_opt2': 'bar'},
     }
     with task_manager.acquire(self.context, self.node.uuid) as task:
         res = neutron.get_local_group_information(task, pg)
     self.assertEqual(expected, res)
Exemplo n.º 44
0
 def test_vif_list_internal(self):
     vif_id = uuidutils.generate_uuid()
     self.port.internal_info = {common.TENANT_VIF_KEY: vif_id}
     self.port.save()
     pg_vif_id = uuidutils.generate_uuid()
     portgroup = obj_utils.create_test_portgroup(
         self.context,
         node_id=self.node.id,
         address='52:54:00:00:00:00',
         internal_info={common.TENANT_VIF_KEY: pg_vif_id})
     obj_utils.create_test_port(self.context,
                                node_id=self.node.id,
                                portgroup_id=portgroup.id,
                                address='52:54:00:cf:2d:01',
                                uuid=uuidutils.generate_uuid())
     with task_manager.acquire(self.context, self.node.id) as task:
         vifs = self.interface.vif_list(task)
         self.assertItemsEqual([{'id': pg_vif_id}, {'id': vif_id}], vifs)
Exemplo n.º 45
0
 def test_portgroup_changed(self):
     portgroup = utils.create_test_portgroup(self.context)
     with task_manager.acquire(self.context, self.node.id) as task:
         self.interface.portgroup_changed(task, portgroup)
Exemplo n.º 46
0
 def setUp(self):
     super(GetPhysnetsByPortgroupID, self).setUp()
     self.node = object_utils.create_test_node(self.context)
     self.portgroup = object_utils.create_test_portgroup(
         self.context, node_id=self.node.id)