Beispiel #1
0
 def test_network_associate_host(self, mock_save, mock_get):
     net_obj = objects.Network(context=self.context, id=1)
     mock_get.return_value = net_obj
     host = str(mock.sentinel.host)
     self.network_api.associate(self.context, FAKE_UUID, host=host)
     mock_save.assert_called_once_with()
     self.assertEqual(host, net_obj.host)
Beispiel #2
0
 def test_network_associate_project(self, mock_associate, mock_get):
     net_obj = objects.Network(context=self.context, id=1)
     mock_get.return_value = net_obj
     project = mock.sentinel.project
     self.network_api.associate(self.context, FAKE_UUID, project=project)
     mock_associate.assert_called_once_with(self.context, project,
                                            network_id=net_obj.id,
                                            force=True)
Beispiel #3
0
 def _test_is_multi_host_network_has_project_id(self, is_multi_host,
                                                fip_get):
     network = objects.Network(
         id=123, project_id=self.context.project_id,
         multi_host=is_multi_host)
     fip_get.return_value = [
         objects.FixedIP(instance_uuid=FAKE_UUID, network=network,
                         floating_ips=objects.FloatingIPList())]
     instance = objects.Instance(uuid=FAKE_UUID)
     result, floats = self.network_api._get_multi_addresses(self.context,
                                                            instance)
     self.assertEqual(is_multi_host, result)
Beispiel #4
0
 def test_get_vif_by_mac_address(self, mock_get_by_address,
                                 mock_get_by_id):
     mock_get_by_address.return_value = dict(
         test_virtual_interface.fake_vif, network_id=123)
     mock_get_by_id.return_value = objects.Network(
         uuid=mock.sentinel.network_uuid)
     vif = self.network_api.get_vif_by_mac_address(self.context,
                                                   mock.sentinel.mac)
     self.assertEqual(123, vif.network_id)
     self.assertEqual(str(mock.sentinel.network_uuid), vif.net_uuid)
     mock_get_by_address.assert_called_once_with(self.context,
                                                 mock.sentinel.mac)
     mock_get_by_id.assert_called_once_with(self.context, 123,
                                            project_only='allow_none')
Beispiel #5
0
 def get(self, context, network_id):
     for network in self.networks:
         if network.get('uuid') == network_id:
             if 'injected' in network and network['injected'] is None:
                 # NOTE: This is a workaround for passing unit tests.
                 # When using patron-network, 'injected' value should be
                 # boolean because of the definition of objects.Network().
                 # However, 'injected' value can be None if neutron.
                 # So here changes the value to False just for passing
                 # following _from_db_object().
                 network['injected'] = False
             return objects.Network._from_db_object(context,
                                                    objects.Network(),
                                                    network)
     raise exception.NetworkNotFound(network_id=network_id)
Beispiel #6
0
 def test_get_vifs_by_instance(self, mock_get_by_instance,
                               mock_get_by_id):
     mock_get_by_instance.return_value = [
         dict(test_virtual_interface.fake_vif,
              network_id=123)]
     mock_get_by_id.return_value = objects.Network()
     mock_get_by_id.return_value.uuid = mock.sentinel.network_uuid
     instance = objects.Instance(uuid=mock.sentinel.inst_uuid)
     vifs = self.network_api.get_vifs_by_instance(self.context,
                                                  instance)
     self.assertEqual(1, len(vifs))
     self.assertEqual(123, vifs[0].network_id)
     self.assertEqual(str(mock.sentinel.network_uuid), vifs[0].net_uuid)
     mock_get_by_instance.assert_called_once_with(
         self.context, str(mock.sentinel.inst_uuid), use_slave=False)
     mock_get_by_id.assert_called_once_with(self.context, 123,
                                            project_only='allow_none')
Beispiel #7
0
 def _fake_db_network_get_all(self, context, project_only="allow_none"):
     project_id = context.project_id
     nets = self.networks
     if patron.context.is_user_context(context) and project_only:
         if project_only == 'allow_none':
             nets = [
                 n for n in self.networks if (n['project_id'] == project_id
                                              or n['project_id'] is None)
             ]
         else:
             nets = [
                 n for n in self.networks if n['project_id'] == project_id
             ]
     objs = [
         objects.Network._from_db_object(context, objects.Network(), net)
         for net in nets
     ]
     return objects.NetworkList(objects=objs)
Beispiel #8
0
 def _from_db_object(context, fixedip, db_fixedip, expected_attrs=None):
     if expected_attrs is None:
         expected_attrs = []
     for field in fixedip.fields:
         if field == 'default_route':
             # NOTE(danms): This field is only set when doing a
             # FixedIPList.get_by_network() because it's a relatively
             # special-case thing, so skip it here
             continue
         if field not in FIXED_IP_OPTIONAL_ATTRS:
             fixedip[field] = db_fixedip[field]
     # NOTE(danms): Instance could be deleted, and thus None
     if 'instance' in expected_attrs:
         fixedip.instance = objects.Instance._from_db_object(
             context,
             objects.Instance(context),
             db_fixedip['instance']) if db_fixedip['instance'] else None
     if 'network' in expected_attrs:
         fixedip.network = objects.Network._from_db_object(
             context,
             objects.Network(context),
             db_fixedip['network']) if db_fixedip['network'] else None
     if 'virtual_interface' in expected_attrs:
         db_vif = db_fixedip['virtual_interface']
         vif = objects.VirtualInterface._from_db_object(
             context,
             objects.VirtualInterface(context),
             db_fixedip['virtual_interface']) if db_vif else None
         fixedip.virtual_interface = vif
     if 'floating_ips' in expected_attrs:
         fixedip.floating_ips = obj_base.obj_make_list(
                 context, objects.FloatingIPList(context),
                 objects.FloatingIP, db_fixedip['floating_ips'])
     fixedip._context = context
     fixedip.obj_reset_changes()
     return fixedip
Beispiel #9
0
 def get_all(context):
     ret = objects.NetworkList(context=context, objects=[])
     net = objects.Network(cidr='10.0.0.0/23')
     ret.objects.append(net)
     return ret
Beispiel #10
0
 def test_network_disassociate(self, mock_disassociate, mock_get):
     mock_get.return_value = objects.Network(context=self.context, id=123)
     self.network_api.disassociate(self.context, FAKE_UUID)
     mock_disassociate.assert_called_once_with(self.context, 123,
                                               project=True, host=True)
Beispiel #11
0
 def test_network_disassociate_host(self, mock_disassociate, mock_get):
     net_obj = objects.Network(context=self.context, id=1)
     mock_get.return_value = net_obj
     self.network_api.associate(self.context, FAKE_UUID, host=None)
     mock_disassociate.assert_called_once_with(self.context, net_obj.id,
                                               host=True, project=False)