Esempio n. 1
0
    def test_get_all_capsules_with_pagination_marker(
            self,
            mock_container_get_by_uuid,
            mock_capsule_save,
            mock_capsule_list,
            mock_capsule_show):
        test_container = utils.get_test_container()
        test_container_obj = objects.Container(self.context,
                                               **test_container)
        mock_container_get_by_uuid.return_value = test_container_obj
        capsule_list = []
        for id_ in range(4):
            test_capsule = utils.create_test_container(
                id=id_, uuid=uuidutils.generate_uuid(),
                name='capsule' + str(id_), context=self.context)
            capsule_list.append(objects.Capsule(self.context,
                                                **test_capsule))
        mock_capsule_list.return_value = capsule_list[-1:]
        mock_capsule_show.return_value = capsule_list[-1]
        mock_capsule_save.return_value = True

        response = self.app.get('/v1/capsules/?limit=3&marker=%s'
                                % capsule_list[2].uuid)

        self.assertEqual(200, response.status_int)
        actual_capsules = response.json['capsules']

        self.assertEqual(1, len(actual_capsules))
        self.assertEqual(actual_capsules[-1].get('uuid'),
                         actual_capsules[0].get('uuid'))
Esempio n. 2
0
 def test_validate_container_state(self):
     container = Container(self.context, **db_utils.get_test_container())
     container.status = 'Stopped'
     with self.assertRaisesRegex(exception.InvalidStateException,
                                 "%s" % container.uuid):
         utils.validate_container_state(container, 'stop')
     with self.assertRaisesRegex(exception.InvalidStateException,
                                 "%s" % container.uuid):
         utils.validate_container_state(container, 'pause')
     container.status = 'Running'
     with self.assertRaisesRegex(exception.InvalidStateException,
                                 "%s" % container.uuid):
         utils.validate_container_state(container, 'start')
     with self.assertRaisesRegex(exception.InvalidStateException,
                                 "%s" % container.uuid):
         utils.validate_container_state(container, 'unpause')
     with self.assertRaisesRegex(exception.InvalidStateException,
                                 "%s" % container.uuid):
         utils.validate_container_state(container, 'delete')
     self.assertIsNone(utils.validate_container_state(
         container, 'reboot'))
     container.status = 'Stopped'
     self.assertIsNone(utils.validate_container_state(
         container, 'reboot'))
     container.status = 'Running'
     self.assertIsNone(utils.validate_container_state(
         container, 'execute'))
Esempio n. 3
0
 def setUp(self):
     super(TestAPI, self).setUp()
     self.compute_api = api.API(self.context)
     self.container = objects.Container(
         self.context, **utils.get_test_container())
     self.network = objects.Network(
         self.context, **utils.get_test_network())
Esempio n. 4
0
    def test_get_all_capsules_all_projects(self,
                                           mock_container_get_by_uuid,
                                           mock_capsule_list,
                                           mock_container_show):
        test_container = utils.get_test_container()
        test_container_obj = objects.Container(self.context,
                                               **test_container)
        mock_container_get_by_uuid.return_value = test_container_obj

        test_capsule = utils.create_test_container(context=self.context)
        test_capsule_obj = objects.Capsule(self.context, **test_capsule)
        mock_capsule_list.return_value = [test_capsule_obj]
        mock_container_show.return_value = test_container_obj

        response = self.app.get('/v1/capsules/?all_projects=1')

        mock_capsule_list.assert_called_once_with(mock.ANY,
                                                  1000, None, 'id', 'asc',
                                                  filters=None)
        context = mock_capsule_list.call_args[0][0]
        self.assertIs(True, context.all_projects)
        self.assertEqual(200, response.status_int)
        actual_capsules = response.json['capsules']
        self.assertEqual(1, len(actual_capsules))
        self.assertEqual(test_capsule['uuid'],
                         actual_capsules[0].get('uuid'))
Esempio n. 5
0
    def test_wart_container_event(self, mock_finish, mock_start):
        container = Container(self.context, **db_utils.get_test_container())

        @utils.wrap_container_event(prefix='compute')
        def fake_event(self, context, container):
            pass

        fake_event(self, self.context, container=container)

        self.assertTrue(mock_start.called)
        self.assertTrue(mock_finish.called)
Esempio n. 6
0
 def test_container_delete_with_host_no_tup(self, mock_rpc_call,
                                            mock_list, mock_service_is_up):
     test_container = utils.get_test_container()
     test_container_obj = objects.Container(self.context, **test_container)
     test_service = utils.get_test_zun_service(host="fake_host")
     test_service_obj = objects.ZunService(self.context, **test_service)
     mock_list.return_value = [test_service_obj]
     mock_service_is_up.return_value = False
     self.assertRaises(exception.ContainerHostNotUp,
                       self.compute_rpcapi.container_delete,
                       self.context, test_container_obj, False)
Esempio n. 7
0
def get_test_container(context, **kwargs):
    """Return a test container object with appropriate attributes.

    NOTE: The object leaves the attributes marked as changed, such
    that a create() could be used to commit it to the DB.
    """
    db_container = db_utils.get_test_container(**kwargs)
    container = objects.Container(context)
    for key in db_container:
        setattr(container, key, db_container[key])
    return container
Esempio n. 8
0
    def test_select_destinations_no_valid_host(self, mock_hosts_up):

        def _return_no_host(*args, **kwargs):
            return []

        mock_hosts_up.side_effect = _return_no_host
        test_container = utils.get_test_container()
        containers = [objects.Container(self.context, **test_container)]
        extra_spec = {}
        self.assertRaises(exception.NoValidHost,
                          self.driver_cls().select_destinations, self.context,
                          containers, extra_spec)
Esempio n. 9
0
 def _test_get_container_any_type(self, container_type, container_cls):
     fake_container = utils.get_test_container(
         container_type=container_type)
     uuid = fake_container['uuid']
     with mock.patch.object(self.dbapi, 'get_container_by_uuid',
                            autospec=True) as mock_get_container:
         mock_get_container.return_value = fake_container
         container = objects.Container.get_container_any_type(
             self.context, uuid)
         mock_get_container.assert_called_once_with(
             self.context, consts.TYPE_ANY, uuid)
         self.assertEqual(self.context, container._context)
         self.assertIsInstance(container, container_cls)
Esempio n. 10
0
    def test_wrap_container_event_log_exception(self, mock_finish, mock_start):
        container = Container(self.context, **db_utils.get_test_container())

        @utils.wrap_container_event(prefix='compute')
        def fake_event(self, context, container):
            raise exception.ZunException()

        self.assertRaises(exception.ZunException, fake_event,
                          self, self.context, container=container)

        self.assertTrue(mock_start.called)
        self.assertTrue(mock_finish.called)
        args, kwargs = mock_finish.call_args
        self.assertIsInstance(kwargs['exc_val'], exception.ZunException)
Esempio n. 11
0
 def test_add_security_groups_to_ports(self, mock_neutron_api_cls):
     addresses = {'fake-net-id': [{'port': 'fake-port-id'}]}
     container = Container(self.context, **utils.get_test_container(
         addresses=addresses))
     mock_neutron_api_cls.return_value = self.network_api.neutron_api
     old_port = self.network_api.neutron_api.list_ports(
         id='fake-port-id')['ports'][0]
     security_group_ids = ['sg2']
     self.network_api.add_security_groups_to_ports(container,
                                                   security_group_ids)
     new_port = self.network_api.neutron_api.list_ports(
         id='fake-port-id')['ports'][0]
     old_secgroups = old_port.pop('security_groups')
     new_secgroups = new_port.pop('security_groups')
     self.assertEqual(old_secgroups + ['sg2'], new_secgroups)
     # assert nothing else changed besides security_groups
     self.assertEqual(old_port, new_port)
Esempio n. 12
0
 def test_connect_container_to_network_failed(self, mock_neutron_api_cls):
     container = Container(self.context, **utils.get_test_container())
     network_name = 'c02afe4e-8350-4263-8078'
     requested_net = {'ipv4_address': '10.5.0.22',
                      'port': 'fake-port-id',
                      'preserve_on_delete': True}
     mock_neutron_api_cls.return_value = self.network_api.neutron_api
     old_port = self.network_api.neutron_api.list_ports(
         id='fake-port-id')['ports'][0]
     self.assertEqual('', old_port['device_id'])
     self.network_api.docker = mock.MagicMock()
     self.network_api.docker.connect_container_to_network = \
         mock.Mock(side_effect=exception.DockerError)
     self.assertRaises(exception.DockerError,
                       self.network_api.connect_container_to_network,
                       container, network_name, requested_net)
     new_port = self.network_api.neutron_api.list_ports(
         id='fake-port-id')['ports'][0]
     self.assertEqual('', new_port['device_id'])
Esempio n. 13
0
    def test_add_security_groups_to_ports_bad_update(
            self, mock_neutron_api_cls):
        addresses = {'fake-net-id': [{'port': 'fake-port-id'}]}
        container = Container(self.context, **utils.get_test_container(
            addresses=addresses))
        mock_neutron_api_cls.return_value = self.network_api.neutron_api
        security_group_ids = ['sg2']
        with mock.patch.object(self.network_api.neutron_api,
                               'update_port') as mock_update_port:
            mock_update_port.side_effect = n_exc.BadRequest(
                message='error')
            self.assertRaises(exception.SecurityGroupCannotBeApplied,
                              self.network_api.add_security_groups_to_ports,
                              container, security_group_ids)

        mock_update_port.assert_called_once_with(
            'fake-port-id',
            {'port': {'security_groups': ['sg1', 'sg2']}},
            admin=True)
Esempio n. 14
0
    def test_get_one_by_uuid(self, mock_container_get_by_uuid,
                             mock_capsule_get_by_uuid,
                             mock_container_show):
        test_container = utils.get_test_container()
        test_container_obj = objects.Container(self.context, **test_container)
        mock_container_get_by_uuid.return_value = test_container_obj
        mock_container_show.return_value = test_container_obj

        test_capsule = utils.create_test_container(context=self.context)
        test_capsule_obj = objects.Capsule(self.context, **test_capsule)
        mock_capsule_get_by_uuid.return_value = test_capsule_obj

        response = self.get('/v1/capsules/%s/' % test_capsule['uuid'])

        context = mock_capsule_get_by_uuid.call_args[0][0]
        self.assertIs(False, context.all_projects)
        self.assertEqual(200, response.status_int)
        self.assertEqual(test_capsule['uuid'],
                         response.json['uuid'])
Esempio n. 15
0
 def test_disconnect_container_from_network(self):
     addresses = {'fake-net-id': [{'port': 'fake-port-id',
                                   'preserve_on_delete': False}]}
     container = Container(self.context, **utils.get_test_container(
         addresses=addresses))
     network_name = 'c02afe4e-8350-4263-8078'
     ports = self.network_api.neutron_api.list_ports(
         id='fake-port-id')['ports']
     self.assertEqual(1, len(ports))
     with mock.patch.object(self.network_api.docker,
                            'disconnect_container_from_network'
                            ) as mock_disconnect:
         self.network_api.disconnect_container_from_network(
             container, network_name, 'fake-net-id')
     mock_disconnect.assert_called_once_with(
         container.container_id, network_name)
     # assert the neutron port is deleted
     ports = self.network_api.neutron_api.list_ports(
         id='fake-port-id')['ports']
     self.assertEqual(0, len(ports))
Esempio n. 16
0
    def test_select_destinations(self, mock_random_choice, mock_hosts_up):
        all_hosts = ['host1', 'host2', 'host3', 'host4']

        def _return_hosts(*args, **kwargs):
            return all_hosts

        mock_random_choice.side_effect = ['host3']
        mock_hosts_up.side_effect = _return_hosts

        test_container = utils.get_test_container()
        containers = [objects.Container(self.context, **test_container)]
        extra_spec = {}
        dests = self.driver_cls().select_destinations(self.context, containers,
                                                      extra_spec)

        self.assertEqual(1, len(dests))
        (host, node) = (dests[0]['host'], dests[0]['nodename'])
        self.assertEqual('host3', host)
        self.assertIsNone(node)

        calls = [mock.call(all_hosts)]
        self.assertEqual(calls, mock_random_choice.call_args_list)
Esempio n. 17
0
    def test_connect_container_to_network(self):
        container = Container(self.context, **utils.get_test_container())
        network_name = 'c02afe4e-8350-4263-8078'
        requested_net = {'ipv4_address': '10.5.0.22',
                         'port': 'fake-port-id',
                         'preserve_on_delete': True}
        expected_address = [{'version': 4, 'addr': '10.5.0.22',
                             'port': 'fake-port-id',
                             'subnet_id': 'fake-subnet-id',
                             'preserve_on_delete': True}]
        old_port = self.network_api.neutron_api.list_ports(
            id='fake-port-id')['ports'][0]
        self.assertEqual('', old_port['device_id'])
        with mock.patch.object(self.network_api.docker,
                               'connect_container_to_network') as mock_connect:
            address = self.network_api.connect_container_to_network(
                container, network_name, requested_net)

        self.assertEqual(expected_address, address)
        mock_connect.assert_called_once_with(
            container.container_id, network_name, ipv4_address='10.5.0.22')
        new_port = self.network_api.neutron_api.list_ports(
            id='fake-port-id')['ports'][0]
        self.assertEqual(container.uuid, new_port['device_id'])
Esempio n. 18
0
 def test_container_network_detach(self, mock_detach):
     container = Container(self.context, **utils.get_test_container())
     self.compute_manager.network_detach(self.context, container, 'network')
     mock_detach.assert_called_once_with(self.context, container, mock.ANY)
Esempio n. 19
0
 def test_container_resize_failed(self, mock_resize):
     container = Container(self.context, **utils.get_test_container())
     mock_resize.side_effect = exception.DockerError
     self.assertRaises(exception.DockerError,
                       self.compute_manager.container_resize,
                       self.context, container, "100", "100")
Esempio n. 20
0
 def test_container_resize(self, mock_resize):
     container = Container(self.context, **utils.get_test_container())
     self.compute_manager.container_resize(
         self.context, container, "100", "100")
     mock_resize.assert_called_once_with(
         self.context, container, "100", "100")
Esempio n. 21
0
    def test_select_destinations(self, mock_random_choice, mock_list_by_binary,
                                 mock_compute_list, mock_service_is_up):
        all_services = [
            FakeService('service1', 'host1'),
            FakeService('service2', 'host2'),
            FakeService('service3', 'host3'),
            FakeService('service4', 'host4')
        ]

        def _return_services(*args, **kwargs):
            return all_services

        self.driver.servicegroup_api.service_is_up = mock.Mock(
            return_value=True)
        mock_list_by_binary.side_effect = _return_services
        numa_topology = {
            "nodes": [{
                "id": 0,
                "cpuset": [1, 2, 3, 4],
                "pinned_cpus": [],
                "mem_total": 1024 * 64,
                "mem_available": 1024 * 64
            }, {
                "id": 1,
                "cpuset": [5, 6, 7, 8],
                "pinned_cpus": [],
                "mem_total": 1024 * 64,
                "mem_available": 1024 * 64
            }]
        }
        numa = objects.numa.NUMATopology._from_dict(numa_topology)
        test_container = utils.get_test_container()
        containers = [objects.Container(self.context, **test_container)]
        node1 = objects.ComputeNode(self.context)
        node1.cpus = 48
        node1.cpu_used = 0.0
        node1.mem_total = 1024 * 128
        node1.mem_used = 1024 * 4
        node1.mem_free = 1024 * 124
        node1.mem_available = 1024 * 124
        node1.disk_total = 80
        node1.disk_used = 20
        node1.hostname = 'host1'
        node1.numa_topology = numa
        node1.labels = {}
        node1.pci_device_pools = None
        node1.disk_quota_supported = True
        node1.runtimes = ['runc']
        node1.enable_cpu_pinning = False
        node2 = objects.ComputeNode(self.context)
        node2.cpus = 48
        node2.cpu_used = 0.0
        node2.mem_total = 1024 * 128
        node2.mem_used = 1024 * 4
        node2.mem_free = 1024 * 124
        node2.mem_available = 1024 * 124
        node2.disk_total = 80
        node2.disk_used = 20
        node2.hostname = 'host2'
        node2.numa_topology = numa
        node2.labels = {}
        node2.pci_device_pools = None
        node2.disk_quota_supported = True
        node2.runtimes = ['runc']
        node2.enable_cpu_pinning = False
        node3 = objects.ComputeNode(self.context)
        node3.cpus = 48
        node3.cpu_used = 0.0
        node3.mem_total = 1024 * 128
        node3.mem_used = 1024 * 4
        node3.mem_free = 1024 * 124
        node3.mem_available = 1024 * 124
        node3.disk_total = 80
        node3.disk_used = 20
        node3.hostname = 'host3'
        node3.numa_topology = numa
        node3.labels = {}
        node3.pci_device_pools = None
        node3.disk_quota_supported = True
        node3.runtimes = ['runc']
        node3.enable_cpu_pinning = False
        node4 = objects.ComputeNode(self.context)
        node4.cpus = 48
        node4.cpu_used = 0.0
        node4.mem_total = 1024 * 128
        node4.mem_used = 1024 * 4
        node4.mem_free = 1024 * 124
        node4.mem_available = 1024 * 124
        node4.disk_total = 80
        node4.disk_used = 20
        node4.hostname = 'host4'
        node4.numa_topology = numa
        node4.labels = {}
        node4.pci_device_pools = None
        node4.disk_quota_supported = True
        node4.runtimes = ['runc']
        node4.enable_cpu_pinning = False
        nodes = [node1, node2, node3, node4]
        mock_compute_list.return_value = nodes

        def side_effect(hosts):
            return hosts[2]

        mock_random_choice.side_effect = side_effect
        mock_service_is_up.return_value = True
        extra_spec = {}
        dests = self.driver.select_destinations(self.context, containers,
                                                extra_spec)

        self.assertEqual(1, len(dests))
        (host, node) = (dests[0]['host'], dests[0]['nodename'])
        self.assertEqual('host3', host)
        self.assertIsNone(node)
Esempio n. 22
0
 def setUp(self):
     super(TestContainerObject, self).setUp()
     self.fake_container = utils.get_test_container()
Esempio n. 23
0
    def test_select_destinations(self, mock_random_choice, mock_list_by_binary,
                                 mock_compute_list, mock_service_is_up):
        all_services = [
            FakeService('service1', 'host1'),
            FakeService('service2', 'host2'),
            FakeService('service3', 'host3'),
            FakeService('service4', 'host4')
        ]

        def _return_services(*args, **kwargs):
            return all_services

        self.driver.servicegroup_api.service_is_up = mock.Mock(
            return_value=True)
        mock_list_by_binary.side_effect = _return_services
        test_container = utils.get_test_container()
        containers = [objects.Container(self.context, **test_container)]
        node1 = objects.ComputeNode(self.context)
        node1.cpus = 48
        node1.cpu_used = 0.0
        node1.mem_total = 1024 * 128
        node1.mem_used = 1024 * 4
        node1.mem_free = 1024 * 124
        node1.disk_total = 80
        node1.disk_used = 20
        node1.hostname = 'host1'
        node1.numa_topology = None
        node1.labels = {}
        node1.pci_device_pools = None
        node1.disk_quota_supported = True
        node2 = objects.ComputeNode(self.context)
        node2.cpus = 48
        node2.cpu_used = 0.0
        node2.mem_total = 1024 * 128
        node2.mem_used = 1024 * 4
        node2.mem_free = 1024 * 124
        node2.disk_total = 80
        node2.disk_used = 20
        node2.hostname = 'host2'
        node2.numa_topology = None
        node2.labels = {}
        node2.pci_device_pools = None
        node2.disk_quota_supported = True
        node3 = objects.ComputeNode(self.context)
        node3.cpus = 48
        node3.cpu_used = 0.0
        node3.mem_total = 1024 * 128
        node3.mem_used = 1024 * 4
        node3.mem_free = 1024 * 124
        node3.disk_total = 80
        node3.disk_used = 20
        node3.hostname = 'host3'
        node3.numa_topology = None
        node3.labels = {}
        node3.pci_device_pools = None
        node3.disk_quota_supported = True
        node4 = objects.ComputeNode(self.context)
        node4.cpus = 48
        node4.cpu_used = 0.0
        node4.mem_total = 1024 * 128
        node4.mem_used = 1024 * 4
        node4.mem_free = 1024 * 124
        node4.disk_total = 80
        node4.disk_used = 20
        node4.hostname = 'host4'
        node4.numa_topology = None
        node4.labels = {}
        node4.pci_device_pools = None
        node4.disk_quota_supported = True
        nodes = [node1, node2, node3, node4]
        mock_compute_list.return_value = nodes

        def side_effect(hosts):
            return hosts[2]

        mock_random_choice.side_effect = side_effect
        mock_service_is_up.return_value = True
        extra_spec = {}
        dests = self.driver.select_destinations(self.context, containers,
                                                extra_spec)

        self.assertEqual(1, len(dests))
        (host, node) = (dests[0]['host'], dests[0]['nodename'])
        self.assertEqual('host3', host)
        self.assertIsNone(node)
Esempio n. 24
0
 def test_heal_with_rebuilding_exception(self, mock_container_rebuild):
     container = Container(self.context, **utils.get_test_container())
     container.status = consts.RUNNING
     mock_container_rebuild.side_effect = Exception
     self.driver.heal_with_rebuilding_container(
         self.context, container, mock.Mock())
Esempio n. 25
0
 def test_container_unpause(self, mock_unpause):
     container = Container(self.context, **utils.get_test_container())
     self.compute_manager._do_container_unpause(self.context, container)
     mock_unpause.assert_called_once_with(self.context, container)
Esempio n. 26
0
 def test_container_start(self, mock_start, mock_save):
     container = Container(self.context, **utils.get_test_container())
     self.compute_manager._do_container_start(self.context, container)
     mock_save.assert_called_with(self.context)
     mock_start.assert_called_once_with(self.context, container)
Esempio n. 27
0
 def test_container_commit_failed(self, mock_commit):
     container = Container(self.context, **utils.get_test_container())
     mock_commit.side_effect = exception.DockerError
     self.assertRaises(exception.DockerError,
                       self.compute_manager._do_container_commit,
                       self.context, container, 'repo', 'tag')
Esempio n. 28
0
 def setUp(self):
     super(TestContainerObject, self).setUp()
     self.fake_cpuset = utils.get_cpuset_dict()
     self.fake_container = utils.get_test_container(
         cpuset=self.fake_cpuset, cpu_policy='dedicated')
     self.fake_container.pop('capsule_id')
Esempio n. 29
0
 def setUp(self):
     super(TestCapsuleObject, self).setUp()
     self.fake_capsule = utils.get_test_container(
         container_type=consts.TYPE_CAPSULE)
     self.fake_capsule.pop('capsule_id')
Esempio n. 30
0
 def test_container_network_attach(self, mock_attach):
     container = Container(self.context, **utils.get_test_container())
     self.compute_manager.network_attach(self.context, container, 'network')
Esempio n. 31
0
    def test_select_destinations(self, mock_random_choice, mock_list_by_binary,
                                 mock_compute_list, mock_service_is_up):
        all_services = [
            FakeService('service1', 'host1'),
            FakeService('service2', 'host2'),
            FakeService('service3', 'host3'),
            FakeService('service4', 'host4')
        ]

        def _return_services(*args, **kwargs):
            return all_services

        self.driver.servicegroup_api.service_is_up = mock.Mock(
            return_value=True)
        mock_list_by_binary.side_effect = _return_services
        numa_topology = {
            "nodes": [{
                "id": 0,
                "cpuset": [1, 2, 3, 4],
                "pinned_cpus": [],
                "mem_total": 1024 * 64,
                "mem_available": 1024 * 64
            }, {
                "id": 1,
                "cpuset": [5, 6, 7, 8],
                "pinned_cpus": [],
                "mem_total": 1024 * 64,
                "mem_available": 1024 * 64
            }]
        }
        numa = objects.numa.NUMATopology._from_dict(numa_topology)
        test_container = utils.get_test_container()
        containers = [objects.Container(self.context, **test_container)]
        node1 = objects.ComputeNode(self.context)
        node1.rp_uuid = mock.sentinel.node1_rp_uuid
        node1.updated_at = timeutils.utcnow()
        node1.cpus = 48
        node1.cpu_used = 0.0
        node1.mem_total = 1024 * 128
        node1.mem_used = 1024 * 4
        node1.mem_free = 1024 * 124
        node1.mem_available = 1024 * 124
        node1.disk_total = 80
        node1.disk_used = 20
        node1.hostname = 'host1'
        node1.numa_topology = numa
        node1.labels = {}
        node1.pci_device_pools = None
        node1.disk_quota_supported = True
        node1.runtimes = ['runc']
        node1.enable_cpu_pinning = False
        node2 = objects.ComputeNode(self.context)
        node2.rp_uuid = mock.sentinel.node2_rp_uuid
        node2.updated_at = timeutils.utcnow()
        node2.cpus = 48
        node2.cpu_used = 0.0
        node2.mem_total = 1024 * 128
        node2.mem_used = 1024 * 4
        node2.mem_free = 1024 * 124
        node2.mem_available = 1024 * 124
        node2.disk_total = 80
        node2.disk_used = 20
        node2.hostname = 'host2'
        node2.numa_topology = numa
        node2.labels = {}
        node2.pci_device_pools = None
        node2.disk_quota_supported = True
        node2.runtimes = ['runc']
        node2.enable_cpu_pinning = False
        node3 = objects.ComputeNode(self.context)
        node3.rp_uuid = mock.sentinel.node3_rp_uuid
        node3.updated_at = timeutils.utcnow()
        node3.cpus = 48
        node3.cpu_used = 0.0
        node3.mem_total = 1024 * 128
        node3.mem_used = 1024 * 4
        node3.mem_free = 1024 * 124
        node3.mem_available = 1024 * 124
        node3.disk_total = 80
        node3.disk_used = 20
        node3.hostname = 'host3'
        node3.numa_topology = numa
        node3.labels = {}
        node3.pci_device_pools = None
        node3.disk_quota_supported = True
        node3.runtimes = ['runc']
        node3.enable_cpu_pinning = False
        node4 = objects.ComputeNode(self.context)
        node4.rp_uuid = mock.sentinel.node4_rp_uuid
        node4.updated_at = timeutils.utcnow()
        node4.cpus = 48
        node4.cpu_used = 0.0
        node4.mem_total = 1024 * 128
        node4.mem_used = 1024 * 4
        node4.mem_free = 1024 * 124
        node4.mem_available = 1024 * 124
        node4.disk_total = 80
        node4.disk_used = 20
        node4.hostname = 'host4'
        node4.numa_topology = numa
        node4.labels = {}
        node4.pci_device_pools = None
        node4.disk_quota_supported = True
        node4.runtimes = ['runc']
        node4.enable_cpu_pinning = False
        nodes = [node1, node2, node3, node4]
        mock_compute_list.return_value = nodes

        mock_service_is_up.return_value = True
        extra_spec = {}
        mock_alloc_reqs_by_rp_uuid = {
            node3.rp_uuid: [mock.sentinel.node3_alloc_req]
        }
        mock_provider_summaries = {node3.rp_uuid: {}}

        dests = self.driver.select_destinations(
            self.context, containers, extra_spec, mock_alloc_reqs_by_rp_uuid,
            mock_provider_summaries, mock.sentinel.alloc_request_version)

        self.assertEqual(1, len(dests))
        (host, node) = (dests[0]['host'], dests[0]['nodename'])
        self.assertEqual('host3', host)
        self.assertIsNone(node)
        container = containers[0]
        self.mock_placement_client.claim_resources.assert_called_once_with(
            mock.ANY,
            container.uuid,
            mock.sentinel.node3_alloc_req,
            container.project_id,
            container.user_id,
            allocation_request_version=mock.sentinel.alloc_request_version,
            consumer_generation=None)
Esempio n. 32
0
 def setUp(self):
     super(TestContainerObject, self).setUp()
     self.fake_cpuset = utils.get_cpuset_dict()
     self.fake_container = utils.get_test_container(cpuset=self.fake_cpuset,
                                                    cpu_policy='dedicated')
     self.fake_container.pop('capsule_id')
Esempio n. 33
0
 def test_add_security_groups_to_ports(self):
     container = Container(self.context, **utils.get_test_container())
     security_group_ids = ['1234567']
     self.network_api.add_security_groups_to_ports(container,
                                                   security_group_ids)
Esempio n. 34
0
 def test_disconnect_container_from_network(self):
     container = Container(self.context, **utils.get_test_container())
     network_name = 'c02afe4e-8350-4263-8078'
     self.network_api.disconnect_container_from_network(
         container, network_name)
Esempio n. 35
0
 def test_container_update(self, mock_update, mock_save):
     container = Container(self.context, **utils.get_test_container())
     self.compute_manager.container_update(self.context, container,
                                           {'memory': 512})
     mock_save.assert_called_with(self.context)
     mock_update.assert_called_once_with(self.context, container)
Esempio n. 36
0
 def test_heal_with_rebuilding_exception(self, mock_container_rebuild):
     container = Container(self.context, **utils.get_test_container())
     container.status = consts.RUNNING
     mock_container_rebuild.side_effect = Exception
     self.driver.heal_with_rebuilding_container(self.context, container)
Esempio n. 37
0
 def test_container_attach_failed(self, mock_get_websocket_url):
     container = Container(self.context, **utils.get_test_container())
     mock_get_websocket_url.side_effect = Exception
     self.assertRaises(exception.ZunException,
                       self.compute_manager.container_attach,
                       self.context, container)
Esempio n. 38
0
 def test_container_execute_failed(self, mock_execute_create):
     container = Container(self.context, **utils.get_test_container())
     mock_execute_create.side_effect = exception.DockerError
     self.assertRaises(exception.DockerError,
                       self.compute_manager.container_exec,
                       self.context, container, 'fake_cmd', True, False)
Esempio n. 39
0
 def setUp(self):
     super(TestCapsuleObject, self).setUp()
     self.fake_capsule = utils.get_test_container(
         container_type=consts.TYPE_CAPSULE)
     self.fake_capsule.pop('capsule_id')
Esempio n. 40
0
 def test_container_show(self, mock_show):
     container = Container(self.context, **utils.get_test_container())
     self.compute_manager.container_show(self.context, container)
     mock_show.assert_called_once_with(self.context, container)
Esempio n. 41
0
 def test_container_kill(self, mock_kill):
     container = Container(self.context, **utils.get_test_container())
     self.compute_manager._do_container_kill(self.context, container, None)
     mock_kill.assert_called_once_with(self.context, container, None)
Esempio n. 42
0
 def test_container_show_failed(self, mock_show):
     container = Container(self.context, **utils.get_test_container())
     mock_show.side_effect = exception.DockerError
     self.assertRaises(exception.DockerError,
                       self.compute_manager.container_show,
                       self.context, container)
Esempio n. 43
0
 def test_container_logs_failed(self, mock_logs):
     container = Container(self.context, **utils.get_test_container())
     mock_logs.side_effect = exception.DockerError
     self.assertRaises(exception.DockerError,
                       self.compute_manager.container_logs, self.context,
                       container, True, True, False, 'all', None)