コード例 #1
0
    def test_list_containers_with_filters(self):
        container1 = utils.create_test_container(
            name='container-one',
            uuid=uuidutils.generate_uuid(),
            context=self.context)
        container2 = utils.create_test_container(
            name='container-two',
            uuid=uuidutils.generate_uuid(),
            context=self.context)

        res = dbapi.list_containers(self.context,
                                    consts.TYPE_CONTAINER,
                                    filters={'name': 'container-one'})
        self.assertEqual([container1.id], [r.id for r in res])

        res = dbapi.list_containers(self.context,
                                    consts.TYPE_CONTAINER,
                                    filters={'name': 'container-two'})
        self.assertEqual([container2.id], [r.id for r in res])

        res = dbapi.list_containers(self.context,
                                    consts.TYPE_CONTAINER,
                                    filters={'name': 'bad-container'})
        self.assertEqual([], [r.id for r in res])

        res = dbapi.list_containers(self.context,
                                    consts.TYPE_CONTAINER,
                                    filters={'name': container1.name})
        self.assertEqual([container1.id], [r.id for r in res])
コード例 #2
0
ファイル: test_container.py プロジェクト: openstack/higgins
    def test_list_containers_with_filters(self):
        container1 = utils.create_test_container(
            name='container-one',
            uuid=uuidutils.generate_uuid(),
            context=self.context)
        container2 = utils.create_test_container(
            name='container-two',
            uuid=uuidutils.generate_uuid(),
            context=self.context)

        res = dbapi.list_containers(
            self.context, consts.TYPE_CONTAINER,
            filters={'name': 'container-one'})
        self.assertEqual([container1.id], [r.id for r in res])

        res = dbapi.list_containers(
            self.context, consts.TYPE_CONTAINER,
            filters={'name': 'container-two'})
        self.assertEqual([container2.id], [r.id for r in res])

        res = dbapi.list_containers(
            self.context, consts.TYPE_CONTAINER,
            filters={'name': 'bad-container'})
        self.assertEqual([], [r.id for r in res])

        res = dbapi.list_containers(
            self.context, consts.TYPE_CONTAINER,
            filters={'name': container1.name})
        self.assertEqual([container1.id], [r.id for r in res])
コード例 #3
0
ファイル: test_container.py プロジェクト: ppatel826/zun
    def test_list_containers_with_filters(self, mock_write, mock_read):
        mock_read.side_effect = etcd.EtcdKeyNotFound

        container1 = utils.create_test_container(
            name='container-one',
            uuid=uuidutils.generate_uuid(),
            context=self.context)
        container2 = utils.create_test_container(
            name='container-two',
            uuid=uuidutils.generate_uuid(),
            context=self.context)

        mock_read.side_effect = lambda *args: FakeEtcdMultipleResult(
            [container1.as_dict(), container2.as_dict()])

        res = dbapi.list_containers(self.context,
                                    filters={'name': 'container-one'})
        self.assertEqual([container1.id], [r.id for r in res])

        res = dbapi.list_containers(self.context,
                                    filters={'name': 'container-two'})
        self.assertEqual([container2.id], [r.id for r in res])

        res = dbapi.list_containers(self.context,
                                    filters={'name': 'container-three'})
        self.assertEqual([], [r.id for r in res])

        res = dbapi.list_containers(self.context,
                                    filters={'name': container1.name})
        self.assertEqual([container1.id], [r.id for r in res])
コード例 #4
0
ファイル: test_container.py プロジェクト: ppatel826/zun
 def test_create_container_already_exists(self, mock_write, mock_read):
     CONF.set_override("unique_container_name_scope", "", group="compute")
     mock_read.side_effect = etcd.EtcdKeyNotFound
     utils.create_test_container(context=self.context)
     mock_read.side_effect = lambda *args: None
     self.assertRaises(exception.ResourceExists,
                       utils.create_test_container,
                       context=self.context)
コード例 #5
0
 def test_create_container_already_exists(self):
     CONF.set_override("unique_container_name_scope",
                       "",
                       group="compute",
                       enforce_type=True)
     utils.create_test_container(context=self.context, uuid='123')
     with self.assertRaisesRegexp(exception.ContainerAlreadyExists,
                                  'A container with UUID 123.*'):
         utils.create_test_container(context=self.context, uuid='123')
コード例 #6
0
ファイル: test_container.py プロジェクト: openstack/higgins
 def test_create_container_already_exists(self):
     CONF.set_override("unique_container_name_scope", "",
                       group="compute")
     utils.create_test_container(context=self.context,
                                 uuid='123')
     with self.assertRaisesRegex(exception.ContainerAlreadyExists,
                                 'A container with UUID 123.*'):
         utils.create_test_container(context=self.context,
                                     uuid='123')
コード例 #7
0
ファイル: test_container.py プロジェクト: ppatel826/zun
 def test_create_container_already_exists_in_default_name_space(
         self, mock_list_containers, mock_write, mock_read):
     mock_read.side_effect = etcd.EtcdKeyNotFound
     mock_list_containers.return_value = []
     CONF.set_override("unique_container_name_scope", "", group="compute")
     container1 = utils.create_test_container(
         context=self.context, name='cont1', uuid=uuidutils.generate_uuid())
     mock_list_containers.return_value = [container1]
     self.context.project_id = 'fake_project_1'
     self.context.user_id = 'fake_user_1'
     utils.create_test_container(context=self.context,
                                 name='cont1',
                                 uuid=uuidutils.generate_uuid())
コード例 #8
0
    def test_list_containers_with_list_filters(self):
        container1 = utils.create_test_container(
            name='container-one',
            uuid=uuidutils.generate_uuid(),
            context=self.context)
        container2 = utils.create_test_container(
            name='container-two',
            uuid=uuidutils.generate_uuid(),
            context=self.context)

        res = dbapi.list_containers(
            self.context, filters={'name': ['container-one', 'container-two']})
        uuids = sorted([container1.uuid, container2.uuid])
        self.assertEqual(uuids, sorted([r.uuid for r in res]))
コード例 #9
0
 def test_update_container_with_the_same_name(self):
     container1 = utils.create_test_container(
         name='container-one',
         uuid=uuidutils.generate_uuid(),
         context=self.context)
     container2 = utils.create_test_container(
         name='container-two',
         uuid=uuidutils.generate_uuid(),
         context=self.context)
     new_name = 'new_name'
     dbapi.update_container(self.context, container1.id, {'name': new_name})
     self.assertRaises(exception.ContainerAlreadyExists,
                       dbapi.update_container, self.context, container2.id,
                       {'name': new_name})
コード例 #10
0
ファイル: test_container.py プロジェクト: ppatel826/zun
 def test_create_container_already_exists_in_project_name_space(
         self, mock_list_containers, mock_write, mock_read):
     mock_read.side_effect = etcd.EtcdKeyNotFound
     mock_list_containers.return_value = []
     CONF.set_override("unique_container_name_scope",
                       "project",
                       group="compute")
     container1 = utils.create_test_container(context=self.context,
                                              name='cont1')
     mock_list_containers.return_value = [container1]
     with self.assertRaisesRegex(exception.ContainerAlreadyExists,
                                 'A container with name.*'):
         utils.create_test_container(uuid=uuidutils.generate_uuid(),
                                     context=self.context,
                                     name='cont1')
コード例 #11
0
    def _create_action_values(self, uuid, action='create_container'):
        utils.create_test_container(context=self.context,
                                    name='cont1',
                                    uuid=uuid)

        values = {
            'action': action,
            'container_uuid': uuid,
            'request_id': self.context.request_id,
            'user_id': self.context.user_id,
            'project_id': self.context.project_id,
            'start_time': timeutils.utcnow(),
            'message': 'action-message'
        }
        return values
コード例 #12
0
ファイル: test_container.py プロジェクト: openstack/higgins
    def test_list_containers_with_list_filters(self):
        container1 = utils.create_test_container(
            name='container-one',
            uuid=uuidutils.generate_uuid(),
            context=self.context)
        container2 = utils.create_test_container(
            name='container-two',
            uuid=uuidutils.generate_uuid(),
            context=self.context)

        res = dbapi.list_containers(
            self.context, consts.TYPE_CONTAINER,
            filters={'name': ['container-one', 'container-two']})
        uuids = sorted([container1.uuid, container2.uuid])
        self.assertEqual(uuids, sorted([r.uuid for r in res]))
コード例 #13
0
ファイル: test_capsules.py プロジェクト: openstack/higgins
    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'))
コード例 #14
0
 def test_get_container_by_name(self):
     container = utils.create_test_container(context=self.context)
     res = dbapi.get_container_by_name(self.context,
                                       container.container_type,
                                       container.name)
     self.assertEqual(container.id, res.id)
     self.assertEqual(container.uuid, res.uuid)
コード例 #15
0
ファイル: test_container.py プロジェクト: ppatel826/zun
 def test_destroy_container(self, mock_delete, mock_write, mock_read):
     mock_read.side_effect = etcd.EtcdKeyNotFound
     container = utils.create_test_container(context=self.context)
     mock_read.side_effect = lambda *args: FakeEtcdResult(container.as_dict(
     ))
     dbapi.destroy_container(self.context, container.uuid)
     mock_delete.assert_called_once_with('/containers/%s' % container.uuid)
コード例 #16
0
ファイル: test_docker_driver.py プロジェクト: prameswar/zun
 def test_create_sandbox(self, mock_find_container_by_server_name,
                         mock_ensure_active, mock_nova_client,
                         mock_get_sandbox_name):
     nova_client_instance = mock.MagicMock()
     nova_client_instance.create_server.return_value = 'server_instance'
     mock_get_sandbox_name.return_value = 'test_sanbox_name'
     mock_nova_client.return_value = nova_client_instance
     mock_ensure_active.return_value = True
     mock_find_container_by_server_name.return_value = \
         'test_container_name_id'
     db_container = db_utils.create_test_container(context=self.context,
                                                   host=conf.CONF.host)
     mock_container = mock.MagicMock(**db_container)
     result_sandbox_id = self.driver.create_sandbox(self.context,
                                                    mock_container)
     mock_get_sandbox_name.assert_called_once_with(mock_container)
     nova_client_instance.create_server.assert_called_once_with(
         name='test_sanbox_name',
         image='kubernetes/pause',
         flavor='m1.small',
         key_name=None,
         nics='auto',
         availability_zone=':{0}:'.format(conf.CONF.host))
     mock_ensure_active.assert_called_once_with(nova_client_instance,
                                                'server_instance')
     mock_find_container_by_server_name.assert_called_once_with(
         'test_sanbox_name')
     self.assertEqual(result_sandbox_id, 'test_container_name_id')
コード例 #17
0
 def test_destroy_container_by_uuid(self):
     container = utils.create_test_container(context=self.context)
     dbapi.destroy_container(self.context, container.container_type,
                             container.uuid)
     self.assertRaises(exception.ContainerNotFound,
                       dbapi.get_container_by_uuid, self.context,
                       container.container_type, container.uuid)
コード例 #18
0
ファイル: test_container.py プロジェクト: openstack/higgins
 def test_get_container_by_uuid(self):
     container = utils.create_test_container(context=self.context)
     res = dbapi.get_container_by_uuid(self.context,
                                       container.container_type,
                                       container.uuid)
     self.assertEqual(container.id, res.id)
     self.assertEqual(container.uuid, res.uuid)
コード例 #19
0
ファイル: test_capsules.py プロジェクト: wanghuiict/zun
    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'))
コード例 #20
0
ファイル: test_capsules.py プロジェクト: openstack/higgins
    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'))
コード例 #21
0
ファイル: test_capsules.py プロジェクト: wanghuiict/zun
    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'))
コード例 #22
0
    def test_update_container_with_the_same_name(self, mock_update, mock_write,
                                                 mock_read):
        mock_read.side_effect = etcd.EtcdKeyNotFound
        container1 = utils.create_test_container(
            name='container-one',
            uuid=uuidutils.generate_uuid(),
            context=self.context)
        container2 = utils.create_test_container(
            name='container-two',
            uuid=uuidutils.generate_uuid(),
            context=self.context)

        mock_read.side_effect = lambda *args: FakeEtcdMutlipleResult(
            [container1.as_dict(), container2.as_dict()])
        self.assertRaises(exception.ContainerAlreadyExists,
                          dbapi.update_container, self.context,
                          container2.uuid, {'name': 'container-one'})
コード例 #23
0
ファイル: test_containers.py プロジェクト: prameswar/zun
 def test_delete_by_uuid_invalid_state_force_true(self, mock_delete):
     uuid = uuidutils.generate_uuid()
     test_object = utils.create_test_container(context=self.context,
                                               uuid=uuid,
                                               status='Running')
     response = self.app.delete('/v1/containers/%s?force=True' %
                                (test_object.uuid))
     self.assertEqual(204, response.status_int)
コード例 #24
0
ファイル: test_container.py プロジェクト: ppatel826/zun
 def test_update_container_with_the_same_name(self):
     CONF.set_override("unique_container_name_scope",
                       "project",
                       group="compute")
     container1 = utils.create_test_container(
         name='container-one',
         uuid=uuidutils.generate_uuid(),
         context=self.context)
     container2 = utils.create_test_container(
         name='container-two',
         uuid=uuidutils.generate_uuid(),
         context=self.context)
     new_name = 'new_name'
     dbapi.update_container(self.context, container1.id, {'name': new_name})
     self.assertRaises(exception.ContainerAlreadyExists,
                       dbapi.update_container, self.context, container2.id,
                       {'name': new_name})
コード例 #25
0
ファイル: test_containers.py プロジェクト: prameswar/zun
 def test_delete_by_uuid_with_force_wrong(self, mock_delete):
     uuid = uuidutils.generate_uuid()
     test_object = utils.create_test_container(context=self.context,
                                               uuid=uuid)
     mock_delete.side_effect = exception.InvalidValue
     self.assertRaises(AppError, self.app.delete,
                       '/v1/containers/%s?force=wrong' % test_object.uuid)
     self.assertTrue(mock_delete.not_called)
コード例 #26
0
ファイル: test_container.py プロジェクト: ppatel826/zun
 def test_get_container_by_name(self, mock_write, mock_read):
     mock_read.side_effect = etcd.EtcdKeyNotFound
     container = utils.create_test_container(context=self.context)
     mock_read.side_effect = lambda *args: FakeEtcdMultipleResult(
         [container.as_dict()])
     res = dbapi.get_container_by_name(self.context, container.name)
     self.assertEqual(container.id, res.id)
     self.assertEqual(container.uuid, res.uuid)
コード例 #27
0
ファイル: test_containers.py プロジェクト: prameswar/zun
 def test_stop_by_uuid_invalid_state(self):
     uuid = uuidutils.generate_uuid()
     test_object = utils.create_test_container(context=self.context,
                                               uuid=uuid,
                                               status='Stopped')
     with self.assertRaisesRegexp(
             AppError, "Cannot stop container %s in Stopped state" % uuid):
         self.app.post('/v1/containers/%s/%s/' % (test_object.uuid, 'stop'))
コード例 #28
0
ファイル: test_container.py プロジェクト: openstack/higgins
 def test_destroy_container_by_uuid(self):
     container = utils.create_test_container(context=self.context)
     dbapi.destroy_container(self.context, container.container_type,
                             container.uuid)
     self.assertRaises(exception.ContainerNotFound,
                       dbapi.get_container_by_uuid,
                       self.context, container.container_type,
                       container.uuid)
コード例 #29
0
ファイル: test_containers.py プロジェクト: prameswar/zun
 def test_delete_by_uuid_invalid_state(self):
     uuid = uuidutils.generate_uuid()
     test_object = utils.create_test_container(context=self.context,
                                               uuid=uuid,
                                               status='Running')
     with self.assertRaisesRegexp(
             AppError,
             "Cannot delete container %s in Running state" % uuid):
         self.app.delete('/v1/containers/%s' % (test_object.uuid))
コード例 #30
0
    def test_update_container(self):
        container = utils.create_test_container(context=self.context)
        old_image = container.image
        new_image = 'new-image'
        self.assertNotEqual(old_image, new_image)

        res = dbapi.update_container(self.context, container.container_type,
                                     container.id, {'image': new_image})
        self.assertEqual(new_image, res.image)
コード例 #31
0
 def test_get_container_by_uuid(self, mock_inst, mock_write, mock_read):
     mock_inst.return_value = etcdapi.get_backend()
     mock_read.side_effect = etcd.EtcdKeyNotFound
     container = utils.create_test_container(context=self.context)
     mock_read.side_effect = lambda *args: FakeEtcdResult(container.as_dict(
     ))
     res = dbapi.get_container_by_uuid(self.context, container.uuid)
     self.assertEqual(container.id, res.id)
     self.assertEqual(container.uuid, res.uuid)
コード例 #32
0
 def test_create_container_already_exists_in_global_name_space(
         self, mock_list_container, mock_write, mock_read):
     mock_read.side_effect = etcd.EtcdKeyNotFound
     mock_list_container.return_value = []
     CONF.set_override("unique_container_name_scope",
                       "global",
                       group="compute",
                       enforce_type=True)
     container1 = utils.create_test_container(context=self.context,
                                              name='cont1')
     self.context.project_id = 'fake_project_1'
     self.context.user_id = 'fake_user_1'
     mock_list_container.return_value = [container1]
     with self.assertRaisesRegexp(exception.ContainerAlreadyExists,
                                  'A container with name.*'):
         utils.create_test_container(uuid=uuidutils.generate_uuid(),
                                     context=self.context,
                                     name='cont1')
コード例 #33
0
ファイル: test_containers.py プロジェクト: prameswar/zun
 def test_kill_by_uuid_invalid_state(self):
     uuid = uuidutils.generate_uuid()
     test_object = utils.create_test_container(context=self.context,
                                               uuid=uuid,
                                               status='Stopped')
     body = {'signal': 9}
     with self.assertRaisesRegexp(
             AppError, "Cannot kill container %s in Stopped state" % uuid):
         self.app.post('/v1/containers/%s/%s/' % (test_object.uuid, 'kill'),
                       body)
コード例 #34
0
ファイル: test_container.py プロジェクト: openstack/higgins
 def test_update_container_with_the_same_name(self):
     CONF.set_override("unique_container_name_scope", "project",
                       group="compute")
     container1 = utils.create_test_container(
         name='container-one',
         uuid=uuidutils.generate_uuid(),
         context=self.context)
     container2 = utils.create_test_container(
         name='container-two',
         uuid=uuidutils.generate_uuid(),
         context=self.context)
     new_name = 'new_name'
     dbapi.update_container(self.context, container1.container_type,
                            container1.id,
                            {'name': new_name})
     self.assertRaises(exception.ContainerAlreadyExists,
                       dbapi.update_container, self.context,
                       container2.container_type,
                       container2.id, {'name': new_name})
コード例 #35
0
ファイル: test_container.py プロジェクト: openstack/higgins
    def test_update_container(self):
        container = utils.create_test_container(context=self.context)
        old_image = container.image
        new_image = 'new-image'
        self.assertNotEqual(old_image, new_image)

        res = dbapi.update_container(self.context, container.container_type,
                                     container.id,
                                     {'image': new_image})
        self.assertEqual(new_image, res.image)
コード例 #36
0
ファイル: test_containers.py プロジェクト: prameswar/zun
 def test_exec_command_by_uuid_invalid_state(self):
     uuid = uuidutils.generate_uuid()
     test_object = utils.create_test_container(context=self.context,
                                               uuid=uuid,
                                               status='Stopped')
     cmd = {'command': 'ls'}
     with self.assertRaisesRegexp(
             AppError,
             "Cannot execute container %s in Stopped state" % uuid):
         self.app.post(
             '/v1/containers/%s/%s/' % (test_object.uuid, 'execute'), cmd)
コード例 #37
0
ファイル: test_container.py プロジェクト: openstack/higgins
 def test_list_containers(self):
     uuids = []
     for i in range(1, 6):
         container = utils.create_test_container(
             uuid=uuidutils.generate_uuid(),
             context=self.context,
             name='container' + str(i))
         uuids.append(six.text_type(container['uuid']))
     res = dbapi.list_containers(self.context, consts.TYPE_CONTAINER)
     res_uuids = [r.uuid for r in res]
     self.assertEqual(sorted(uuids), sorted(res_uuids))
コード例 #38
0
ファイル: test_docker_driver.py プロジェクト: prameswar/zun
 def setUp(self):
     super(TestDockerDriver, self).setUp()
     self.driver = DockerDriver()
     dfc_patcher = mock.patch.object(docker_utils, 'docker_client')
     docker_client = dfc_patcher.start()
     self.dfc_context_manager = docker_client.return_value
     self.mock_docker = mock.MagicMock()
     container_dict = db_utils.create_test_container(context=self.context)
     self.mock_default_container = mock.MagicMock(**container_dict)
     self.dfc_context_manager.__enter__.return_value = self.mock_docker
     self.addCleanup(dfc_patcher.stop)
コード例 #39
0
 def test_list_containers(self):
     uuids = []
     for i in range(1, 6):
         container = utils.create_test_container(
             uuid=uuidutils.generate_uuid(),
             context=self.context,
             name='container' + str(i))
         uuids.append(six.text_type(container['uuid']))
     res = dbapi.list_containers(self.context, consts.TYPE_CONTAINER)
     res_uuids = [r.uuid for r in res]
     self.assertEqual(sorted(uuids), sorted(res_uuids))
コード例 #40
0
ファイル: test_container.py プロジェクト: ppatel826/zun
    def test_update_container(self, mock_update, mock_write, mock_read):
        mock_read.side_effect = etcd.EtcdKeyNotFound
        container = utils.create_test_container(context=self.context)
        new_image = 'new-image'

        mock_read.side_effect = lambda *args: FakeEtcdResult(container.as_dict(
        ))
        dbapi.update_container(self.context, container.uuid,
                               {'image': new_image})
        self.assertEqual(
            new_image,
            json.loads(mock_update.call_args_list[0][0][0].value)['image'])
コード例 #41
0
ファイル: test_container.py プロジェクト: openstack/higgins
 def test_create_container_already_exists_in_project_name_space(self):
     CONF.set_override("unique_container_name_scope", "project",
                       group="compute")
     utils.create_test_container(context=self.context, name='cont1')
     with self.assertRaisesRegex(exception.ContainerAlreadyExists,
                                 'A container with name.*'):
         utils.create_test_container(uuid=uuidutils.generate_uuid(),
                                     context=self.context,
                                     name='cont1')
     utils.create_test_container(context=self.context,
                                 name='abc',
                                 uuid=uuidutils.generate_uuid())
コード例 #42
0
ファイル: test_container.py プロジェクト: openstack/higgins
    def test_list_containers_sorted(self):
        uuids = []
        for i in range(5):
            container = utils.create_test_container(
                uuid=uuidutils.generate_uuid(),
                context=self.context,
                name='container' + str(i))
            uuids.append(six.text_type(container.uuid))
        res = dbapi.list_containers(
            self.context, consts.TYPE_CONTAINER, sort_key='uuid')
        res_uuids = [r.uuid for r in res]
        self.assertEqual(sorted(uuids), res_uuids)

        self.assertRaises(exception.InvalidParameterValue,
                          dbapi.list_containers,
                          self.context,
                          consts.TYPE_CONTAINER,
                          sort_key='foo')
コード例 #43
0
ファイル: test_capsules.py プロジェクト: openstack/higgins
    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'])
コード例 #44
0
ファイル: test_capsules.py プロジェクト: openstack/higgins
    def test_delete_capsule_by_uuid(self, mock_capsule_save,
                                    mock_capsule_get_by_uuid,
                                    mock_capsule_stop,
                                    mock_capsule_delete):
        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
        mock_capsule_save.return_value = True
        mock_capsule_delete.return_value = True

        capsule_uuid = test_capsule.get('uuid')
        response = self.app.delete('/v1/capsules/%s' % capsule_uuid)

        self.assertTrue(mock_capsule_delete.called)
        self.assertTrue(mock_capsule_stop.called)
        self.assertEqual(204, response.status_int)
        context = mock_capsule_save.call_args[0][0]
        self.assertIs(False, context.all_projects)
コード例 #45
0
ファイル: test_container.py プロジェクト: openstack/higgins
 def test_create_container_already_exists_in_default_name_space(self):
     CONF.set_override("unique_container_name_scope", "",
                       group="compute")
     utils.create_test_container(context=self.context,
                                 name='cont1',
                                 uuid=uuidutils.generate_uuid())
     self.context.project_id = 'fake_project_1'
     self.context.user_id = 'fake_user_1'
     utils.create_test_container(context=self.context,
                                 name='cont1',
                                 uuid=uuidutils.generate_uuid())
     utils.create_test_container(context=self.context,
                                 name='abc',
                                 uuid=uuidutils.generate_uuid())
コード例 #46
0
ファイル: test_container.py プロジェクト: openstack/higgins
 def test_create_container(self):
     utils.create_test_container(context=self.context)
コード例 #47
0
ファイル: test_container.py プロジェクト: openstack/higgins
 def test_update_container_uuid(self):
     container = utils.create_test_container(context=self.context)
     self.assertRaises(exception.InvalidParameterValue,
                       dbapi.update_container, self.context,
                       container.container_type,
                       container.id, {'uuid': ''})