def execute(self, lpar_wrap): LOG.info(_LI('Plugging the Network Interfaces to instance %s'), self.instance.name) # Get the current adapters on the system cna_w_list = vm.get_cnas(self.adapter, self.instance, self.host_uuid) # Trim the VIFs down to the ones that haven't yet been created. crt_vifs = [] for vif in self.network_info: for cna_w in cna_w_list: if vm.norm_mac(cna_w.mac) == vif['address']: break else: crt_vifs.append(vif) # If there are no vifs to create, then just exit immediately. if len(crt_vifs) == 0: return [] # Check to see if the LPAR is OK to add VIFs to. modifiable, reason = lpar_wrap.can_modify_io() if not modifiable: LOG.error(_LE('Unable to create VIF(s) for instance %(sys)s. The ' 'VM was in a state where VIF plugging is not ' 'acceptable. The reason from the system is: ' '%(reason)s'), { 'sys': self.instance.name, 'reason': reason }, instance=self.instance) raise exception.VirtualInterfaceCreateException() # For the VIFs, run the creates (and wait for the events back) try: with self.virt_api.wait_for_instance_event( self.instance, self._get_vif_events(), deadline=CONF.vif_plugging_timeout, error_callback=self._vif_callback_failed): for vif in crt_vifs: LOG.info(_LI('Creating VIF with mac %(mac)s for instance ' '%(sys)s'), { 'mac': vif['address'], 'sys': self.instance.name }, instance=self.instance) vm.crt_vif(self.adapter, self.instance, self.host_uuid, vif) except eventlet.timeout.Timeout: LOG.error(_LE('Error waiting for VIF to be created for instance ' '%(sys)s'), {'sys': self.instance.name}, instance=self.instance) raise exception.VirtualInterfaceCreateException() # Return the list of created VIFs. return cna_w_list
def execute(self, lpar_wrap): LOG.info(_LI('Plugging the Network Interfaces to instance %s'), self.instance.name) # Get the current adapters on the system cna_w_list = vm.get_cnas(self.adapter, self.instance, self.host_uuid) # Trim the VIFs down to the ones that haven't yet been created. crt_vifs = [] for vif in self.network_info: for cna_w in cna_w_list: if vm.norm_mac(cna_w.mac) == vif['address']: break else: crt_vifs.append(vif) # If there are no vifs to create, then just exit immediately. if len(crt_vifs) == 0: return [] # Check to see if the LPAR is OK to add VIFs to. modifiable, reason = lpar_wrap.can_modify_io() if not modifiable: LOG.error(_LE('Unable to create VIF(s) for instance %(sys)s. The ' 'VM was in a state where VIF plugging is not ' 'acceptable. The reason from the system is: ' '%(reason)s'), {'sys': self.instance.name, 'reason': reason}, instance=self.instance) raise exception.VirtualInterfaceCreateException() # For the VIFs, run the creates (and wait for the events back) try: with self.virt_api.wait_for_instance_event( self.instance, self._get_vif_events(), deadline=CONF.vif_plugging_timeout, error_callback=self._vif_callback_failed): for vif in crt_vifs: LOG.info(_LI('Creating VIF with mac %(mac)s for instance ' '%(sys)s'), {'mac': vif['address'], 'sys': self.instance.name}, instance=self.instance) vm.crt_vif(self.adapter, self.instance, self.host_uuid, vif) except eventlet.timeout.Timeout: LOG.error(_LE('Error waiting for VIF to be created for instance ' '%(sys)s'), {'sys': self.instance.name}, instance=self.instance) raise exception.VirtualInterfaceCreateException() # Return the list of created VIFs. return cna_w_list
def test_crt_vif(self, mock_crt_cna, mock_pvm_uuid): """Tests that a VIF can be created.""" # Set up the mocks fake_vif = { 'network': { 'meta': { 'vlan': 5 } }, 'address': 'aabbccddeeff' } def validate_of_crt(*kargs, **kwargs): self.assertEqual('fake_host', kargs[1]) self.assertEqual(5, kargs[3]) self.assertEqual('aabbccddeeff', kwargs['mac_addr']) return pvm_net.CNA.bld(self.apt, 5, 'fake_host') mock_crt_cna.side_effect = validate_of_crt # Invoke resp = vm.crt_vif(self.apt, mock.MagicMock(), 'fake_host', fake_vif) # Validate (along with validate method above) self.assertEqual(1, mock_crt_cna.call_count) self.assertIsNotNone(resp) self.assertIsInstance(resp, pvm_net.CNA)
def test_crt_vif(self, mock_crt_cna, mock_pvm_uuid): """Tests that a VIF can be created.""" # Set up the mocks fake_vif = {'network': {'meta': {'vlan': 5}}, 'address': 'aabbccddeeff'} def validate_of_crt(*kargs, **kwargs): self.assertEqual('fake_host', kargs[1]) self.assertEqual(5, kargs[3]) self.assertEqual('aabbccddeeff', kwargs['mac_addr']) mock_crt_cna.side_effect = validate_of_crt # Invoke vm.crt_vif(mock.MagicMock(), mock.MagicMock(), 'fake_host', fake_vif) # Validate (along with validate method above) self.assertEqual(1, mock_crt_cna.call_count)
def execute(self, lpar_wrap): LOG.info(_LI('Plugging the Network Interfaces to instance %s'), self.instance.name) # Get the current adapters on the system cna_w_list = vm.get_cnas(self.adapter, self.instance, self.host_uuid) # Trim the VIFs down to the ones that haven't yet been created. crt_vifs = [] for vif in self.network_info: for cna_w in cna_w_list: if vm.norm_mac(cna_w.mac) == vif['address']: break else: crt_vifs.append(vif) # If there are no vifs to create, then just exit immediately. if len(crt_vifs) == 0: return [] # Check to see if the LPAR is OK to add VIFs to. modifiable, reason = lpar_wrap.can_modify_io() if not modifiable: LOG.error(_LE('Unable to create VIF(s) for instance %(sys)s. The ' 'VM was in a state where VIF plugging is not ' 'acceptable. The reason from the system is: ' '%(reason)s'), {'sys': self.instance.name, 'reason': reason}, instance=self.instance) raise exception.VirtualInterfaceCreateException() # TODO(KYLEH): We're setting up to wait for an instance event. The # event needs to come back to our compute manager so we need to ensure # the instance.host is set to our host. We shouldn't need to do this # but in the evacuate/recreate case it may reflect the old host. # See: https://bugs.launchpad.net/nova/+bug/1535918 undo_host_change = False if self.instance.host != CONF.host: LOG.warning(_LW('Instance was not assigned to this host. ' 'It was assigned to: %s'), self.instance.host, instance=self.instance) # Update the instance... old_host = self.instance.host self.instance.host = CONF.host self.instance.save() undo_host_change = True # For the VIFs, run the creates (and wait for the events back) try: with self.virt_api.wait_for_instance_event( self.instance, self._get_vif_events(), deadline=CONF.vif_plugging_timeout, error_callback=self._vif_callback_failed): for vif in crt_vifs: LOG.info(_LI('Creating VIF with mac %(mac)s for instance ' '%(sys)s'), {'mac': vif['address'], 'sys': self.instance.name}, instance=self.instance) vm.crt_vif(self.adapter, self.instance, self.host_uuid, vif) except eventlet.timeout.Timeout: LOG.error(_LE('Error waiting for VIF to be created for instance ' '%(sys)s'), {'sys': self.instance.name}, instance=self.instance) raise exception.VirtualInterfaceCreateException() finally: if undo_host_change: LOG.info(_LI('Undoing temporary host assignment to instance.'), instance=self.instance) self.instance.host = old_host self.instance.save() # Return the list of created VIFs. return cna_w_list
def execute(self, lpar_wrap): LOG.info(_LI('Plugging the Network Interfaces to instance %s'), self.instance.name) # Get the current adapters on the system cna_w_list = vm.get_cnas(self.adapter, self.instance, self.host_uuid) # Trim the VIFs down to the ones that haven't yet been created. crt_vifs = [] for vif in self.network_info: for cna_w in cna_w_list: if vm.norm_mac(cna_w.mac) == vif['address']: break else: crt_vifs.append(vif) # If there are no vifs to create, then just exit immediately. if len(crt_vifs) == 0: return [] # Check to see if the LPAR is OK to add VIFs to. modifiable, reason = lpar_wrap.can_modify_io() if not modifiable: LOG.error(_LE('Unable to create VIF(s) for instance %(sys)s. The ' 'VM was in a state where VIF plugging is not ' 'acceptable. The reason from the system is: ' '%(reason)s'), { 'sys': self.instance.name, 'reason': reason }, instance=self.instance) raise exception.VirtualInterfaceCreateException() # TODO(KYLEH): We're setting up to wait for an instance event. The # event needs to come back to our compute manager so we need to ensure # the instance.host is set to our host. We shouldn't need to do this # but in the evacuate/recreate case it may reflect the old host. # See: https://bugs.launchpad.net/nova/+bug/1535918 undo_host_change = False if self.instance.host != CONF.host: LOG.warning(_LW('Instance was not assigned to this host. ' 'It was assigned to: %s'), self.instance.host, instance=self.instance) # Update the instance... old_host = self.instance.host self.instance.host = CONF.host self.instance.save() undo_host_change = True # For the VIFs, run the creates (and wait for the events back) try: with self.virt_api.wait_for_instance_event( self.instance, self._get_vif_events(), deadline=CONF.vif_plugging_timeout, error_callback=self._vif_callback_failed): for vif in crt_vifs: LOG.info(_LI('Creating VIF with mac %(mac)s for instance ' '%(sys)s'), { 'mac': vif['address'], 'sys': self.instance.name }, instance=self.instance) vm.crt_vif(self.adapter, self.instance, self.host_uuid, vif) except eventlet.timeout.Timeout: LOG.error(_LE('Error waiting for VIF to be created for instance ' '%(sys)s'), {'sys': self.instance.name}, instance=self.instance) raise exception.VirtualInterfaceCreateException() finally: if undo_host_change: LOG.info(_LI('Undoing temporary host assignment to instance.'), instance=self.instance) self.instance.host = old_host self.instance.save() # Return the list of created VIFs. return cna_w_list