def test_teardown_network_fails(self, utils_mock, log_mock): # Call fails but method should not fail. # Error will be caught and logged. utils_mock.return_value = ("first-id\nsecond-id\nthird-id\n", None) id = "third-id" network.teardown_network(id) log_mock.warning.assert_called_with(mock.ANY, id)
def test_teardown_network_fails(self, utils_mock, log_mock, mock_os): # Call fails but method should not fail. # Error will be caught and logged. utils_mock.return_value = ("first-id\nsecond-id\nthird-id\n", None) id = "third-id" network.teardown_network(id) log_mock.warning.assert_called_with(mock.ANY, id)
def reboot(self, context, instance, network_info, reboot_type, block_device_info=None, bad_volumes_callback=None): container_id = self._find_container_by_name(instance['name']).get('id') if not container_id: return if not self.docker.stop_container(container_id): LOG.warning(_('Cannot stop the container, ' 'please check docker logs')) return try: network.teardown_network(container_id) self.unplug_vifs(instance, network_info) except Exception: LOG.debug('Cannot destroy the container network during reboot') return if not self.docker.start_container(container_id): LOG.warning(_('Cannot restart the container, ' 'please check docker logs')) return try: self.plug_vifs(instance, network_info) except Exception as e: LOG.warning(_('Cannot setup network on reboot: {0}').format(e)) return
def reboot(self, context, instance, network_info, reboot_type, block_device_info=None, bad_volumes_callback=None): container_id = self._find_container_by_name(instance['name']).get('id') if not container_id: return if not self.docker.stop_container(container_id): LOG.warning( _('Cannot stop the container, ' 'please check docker logs')) return try: network.teardown_network(container_id) self.unplug_vifs(instance, network_info) except Exception: LOG.debug('Cannot destroy the container network during reboot') return if not self.docker.start_container(container_id): LOG.warning( _('Cannot restart the container, ' 'please check docker logs')) return try: self.plug_vifs(instance, network_info) except Exception as e: LOG.warning(_('Cannot setup network on reboot: {0}').format(e)) return
def reboot(self, context, instance, network_info, reboot_type, block_device_info=None, bad_volumes_callback=None): container_id = self._get_container_id(instance) if not container_id: return self._stop(container_id, instance) try: network.teardown_network(container_id) if network_info: self.unplug_vifs(instance, network_info) except Exception as e: LOG.warning(_('Cannot destroy the container network' ' during reboot {0}').format(e), exc_info=True) return binds = self._get_key_binds(container_id, instance) dns = self._extract_dns_entries(network_info) self.docker.start(container_id, binds=binds, dns=dns) try: if network_info: self.plug_vifs(instance, network_info) self._attach_vifs(instance, network_info) except Exception as e: LOG.warning(_('Cannot setup network on reboot: {0}'), e, exc_info=True) return
def reboot(self, context, instance, network_info, reboot_type, block_device_info=None, bad_volumes_callback=None): container_id = self._get_container_id(instance) if not container_id: return self._stop(container_id, instance) try: network.teardown_network(container_id) if network_info: self.unplug_vifs(instance, network_info) except Exception as e: LOG.warning(_('Cannot destroy the container network' ' during reboot {0}').format(e), exc_info=True) return binds = self._get_key_binds(container_id, instance) dns = self._extract_dns_entries(network_info) self.docker.start(container_id, binds=binds, dns=dns) try: if network_info: self.plug_vifs(instance, network_info) except Exception as e: LOG.warning(_('Cannot setup network on reboot: {0}'), e, exc_info=True) return
def destroy(self, context, instance, network_info, block_device_info=None, destroy_disks=True): container_id = self._find_container_by_name(instance['name']).get('id') if not container_id: return self.docker.stop_container(container_id) self.docker.destroy_container(container_id) network.teardown_network(container_id)
def cleanup(self, context, instance, network_info, block_device_info=None, destroy_disks=True, migrate_data=None, destroy_vifs=True): """Cleanup after instance being destroyed by Hypervisor.""" container_id = self._get_container_id(instance) if not container_id: return self.docker.remove_container(container_id, force=True) network.teardown_network(container_id) self.unplug_vifs(instance, network_info)
def test_teardown_delete_network(self, utils_mock, mock_os): id = "second-id" utils_mock.return_value = ("first-id\nsecond-id\nthird-id\n", None) network.teardown_network(id) utils_mock.assert_called_with('ip', 'netns', 'delete', id, run_as_root=True)
def cleanup(self, context, instance, network_info, block_device_info=None, destroy_disks=True): """Cleanup after instance being destroyed by Hypervisor.""" container_id = self._find_container_by_name(instance['name']).get('id') if not container_id: return self.docker.destroy_container(container_id) network.teardown_network(container_id) self.unplug_vifs(instance, network_info)
def cleanup(self, context, instance, network_info, block_device_info=None, destroy_disks=True, migrate_data=None, destroy_vifs=True): """Cleanup after instance being destroyed by Hypervisor.""" container_id = self._get_container_id(instance) if not container_id: return self.docker.remove_container(container_id, force=True) network.teardown_network(container_id) self.unplug_vifs(instance, network_info) if CONF.docker.inject_key: self._cleanup_key(instance, container_id)
def destroy(self, context, instance, network_info, block_device_info=None, destroy_disks=True): container_id = self._find_container_by_name(instance['name']).get('id') if not container_id: return self.docker.stop_container(container_id) self.docker.destroy_container(container_id) network.teardown_network(container_id) self.unplug_vifs(instance, network_info)
def cleanup(self, context, instance, network_info, block_device_info=None, destroy_disks=True, migrate_data=None, destroy_vifs=True): """Cleanup after instance being destroyed by Hypervisor.""" ips=self._extract_ips_entries(network_info) datadir='/data/docker/%s' % ips container_id = self._get_container_id(instance) if not container_id: self.unplug_vifs(instance, network_info) self.vif_driver.cleanup_dir(datadir) return self.docker.remove_container(container_id, force=True) network.teardown_network(container_id) self.unplug_vifs(instance, network_info) self.vif_driver.cleanup_dir(datadir) if CONF.docker.inject_key: self._cleanup_key(instance, container_id)
def cleanup(self, context, instance, network_info, block_device_info=None, destroy_disks=True, migrate_data=None, destroy_vifs=True): """Cleanup after instance being destroyed by Hypervisor.""" ips = self._extract_ips_entries(network_info) datadir = '/data/docker/%s' % ips container_id = self._get_container_id(instance) if not container_id: self.unplug_vifs(instance, network_info) self.vif_driver.cleanup_dir(datadir) return self.docker.remove_container(container_id, force=True) network.teardown_network(container_id) self.unplug_vifs(instance, network_info) self.vif_driver.cleanup_dir(datadir) if CONF.docker.inject_key: self._cleanup_key(instance, container_id)
def test_teardown_network_hyperv(self, utils_mock, mock_os): mock_os.name = 'nt' network.teardown_network("fake_id") self.assertFalse(utils_mock.execute.called)
def test_teardown_network_not_in_list(self, utils_mock, mock_os): utils_mock.return_value = ("first-id\nsecond-id\nthird-id\n", None) network.teardown_network("not-in-list") utils_mock.assert_called_with('ip', '-o', 'netns', 'list')
def test_teardown_delete_network(self, utils_mock): id = "second-id" utils_mock.return_value = ("first-id\nsecond-id\nthird-id\n", None) network.teardown_network(id) utils_mock.assert_called_with('ip', 'netns', 'delete', id, run_as_root=True)
def test_teardown_network_not_in_list(self, utils_mock): utils_mock.return_value = ("first-id\nsecond-id\nthird-id\n", None) network.teardown_network("not-in-list") utils_mock.assert_called_with('ip', '-o', 'netns', 'list')