Ejemplo n.º 1
0
    def test_project_create_invalid_parent(self):
        self.projects_mock.resource_class.__name__ = 'Project'
        self.projects_mock.get.side_effect = exceptions.NotFound(
            'Invalid parent')
        self.projects_mock.find.side_effect = exceptions.NotFound(
            'Invalid parent')

        arglist = [
            '--domain',
            identity_fakes.domain_name,
            '--parent',
            'invalid',
            identity_fakes.project_name,
        ]
        verifylist = [
            ('domain', identity_fakes.domain_name),
            ('parent', 'invalid'),
            ('enable', False),
            ('disable', False),
            ('name', identity_fakes.project_name),
        ]
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        self.assertRaises(
            exceptions.CommandError,
            self.cmd.take_action,
            parsed_args,
        )
Ejemplo n.º 2
0
    def test_image_create_with_unexist_owner(self):
        self.project_mock.get.side_effect = exceptions.NotFound(None)
        self.project_mock.find.side_effect = exceptions.NotFound(None)

        arglist = [
            '--container-format', 'ovf',
            '--disk-format', 'fs',
            '--min-disk', '10',
            '--min-ram', '4',
            '--owner', 'unexist_owner',
            '--protected',
            '--private',
            image_fakes.image_name,
        ]
        verifylist = [
            ('container_format', 'ovf'),
            ('disk_format', 'fs'),
            ('min_disk', 10),
            ('min_ram', 4),
            ('owner', 'unexist_owner'),
            ('protected', True),
            ('unprotected', False),
            ('public', False),
            ('private', True),
            ('name', image_fakes.image_name),
        ]
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        self.assertRaises(
            exceptions.CommandError,
            self.cmd.take_action,
            parsed_args,
        )
Ejemplo n.º 3
0
    def test_flavor_delete_with_unexist_flavor(self):
        self.flavors_mock.get.side_effect = exceptions.NotFound(None)
        self.flavors_mock.find.side_effect = exceptions.NotFound(None)

        arglist = ['unexist_flavor']
        verifylist = [
            ('flavor', 'unexist_flavor'),
        ]

        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        self.assertRaises(exceptions.CommandError, self.cmd.take_action,
                          parsed_args)
Ejemplo n.º 4
0
    def setUp(self):
        super(TestFlavorShow, self).setUp()

        # Return value of _find_resource()
        self.flavors_mock.find.return_value = self.flavor
        self.flavors_mock.get.side_effect = exceptions.NotFound(None)
        self.cmd = flavor.ShowFlavor(self.app, None)
Ejemplo n.º 5
0
    def find(
        self,
        path,
        value=None,
        attr=None,
    ):
        """Find a single resource by name or ID

        :param string path:
            The API-specific portion of the URL path
        :param string search:
            search expression
        :param string attr:
            name of attribute for secondary search
        """

        try:
            ret = self._request('GET', "/%s/%s" % (path, value)).json()
        except ks_exceptions.NotFound:
            kwargs = {attr: value}
            try:
                ret = self.find_one("/%s/detail" % (path), **kwargs)
            except ks_exceptions.NotFound:
                msg = "%s not found" % value
                raise exceptions.NotFound(msg)

        return ret
Ejemplo n.º 6
0
    def test_flavor_unset_with_unexist_flavor(self):
        self.flavors_mock.get.side_effect = exceptions.NotFound(None)
        self.flavors_mock.find.side_effect = exceptions.NotFound(None)

        arglist = [
            '--project', identity_fakes.project_id,
            'unexist_flavor',
        ]
        verifylist = [
            ('project', identity_fakes.project_id),
            ('flavor', 'unexist_flavor'),
        ]
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        self.assertRaises(exceptions.CommandError,
                          self.cmd.take_action,
                          parsed_args)
Ejemplo n.º 7
0
    def test_image_set_with_unexist_project(self):
        self.project_mock.get.side_effect = exceptions.NotFound(None)
        self.project_mock.find.side_effect = exceptions.NotFound(None)

        arglist = [
            '--project',
            'unexist_owner',
            image_fakes.image_id,
        ]
        verifylist = [
            ('project', 'unexist_owner'),
            ('image', image_fakes.image_id),
        ]
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        self.assertRaises(exceptions.CommandError, self.cmd.take_action,
                          parsed_args)
Ejemplo n.º 8
0
 def test_find_resource_find_not_found(self):
     self.manager.get = mock.Mock(side_effect=Exception('Boom!'))
     self.manager.find = mock.Mock(
         side_effect=exceptions.NotFound(404, "2"))
     result = self.assertRaises(exceptions.CommandError,
                                utils.find_resource, self.manager,
                                self.name)
     self.assertEqual("No lego with a name or ID of 'legos' exists.",
                      str(result))
     self.manager.get.assert_called_with(self.name)
     self.manager.find.assert_called_with(display_name=self.name)
Ejemplo n.º 9
0
    def setUp(self):
        super(TestFlavorUnset, self).setUp()

        self.flavors_mock.find.return_value = self.flavor
        self.flavors_mock.get.side_effect = exceptions.NotFound(None)
        # Return a project
        self.projects_mock.get.return_value = fakes.FakeResource(
            None,
            copy.deepcopy(identity_fakes.PROJECT),
            loaded=True,
        )
        self.cmd = flavor.UnsetFlavor(self.app, None)
 def test_wait_for_delete_ok(self, mock_sleep):
     # Tests the normal flow that the resource is deleted with a 404 coming
     # back on the 2nd iteration of the wait loop.
     resource = mock.MagicMock(status='ACTIVE', progress=None)
     mock_get = mock.Mock(side_effect=[resource, exceptions.NotFound(404)])
     manager = mock.MagicMock(get=mock_get)
     res_id = str(uuid.uuid4())
     callback = mock.Mock()
     self.assertTrue(
         utils.wait_for_delete(manager, res_id, callback=callback))
     mock_sleep.assert_called_once_with(5)
     callback.assert_called_once_with(0)
Ejemplo n.º 11
0
    def test_delete_multiple_networks_exception(self):
        arglist = [
            self._networks[0].id,
            'xxxx-yyyy-zzzz',
            self._networks[1].id,
        ]
        verifylist = [
            ('network', arglist),
        ]
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        # Fake exception in find_network()
        ret_find = [
            self._networks[0],
            exceptions.NotFound('404'),
            self._networks[1],
        ]
        self.network.find_network = mock.Mock(side_effect=ret_find)

        # Fake exception in delete_network()
        ret_delete = [
            None,
            exceptions.NotFound('404'),
        ]
        self.network.delete_network = mock.Mock(side_effect=ret_delete)

        self.assertRaises(exceptions.CommandError, self.cmd.take_action,
                          parsed_args)

        # The second call of find_network() should fail. So delete_network()
        # was only called twice.
        calls = [
            call(self._networks[0]),
            call(self._networks[1]),
        ]
        self.network.delete_network.assert_has_calls(calls)
Ejemplo n.º 12
0
    def test_hypervisor_list_matching_option_not_found(self):
        arglist = [
            '--matching',
            'xxx',
        ]
        verifylist = [
            ('matching', 'xxx'),
        ]
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        # Fake exception raised from search()
        self.hypervisors_mock.search.side_effect = exceptions.NotFound(None)

        self.assertRaises(exceptions.NotFound, self.cmd.take_action,
                          parsed_args)
Ejemplo n.º 13
0
    def find_one(self, path, **kwargs):
        """Find a resource by name or ID

        :param string path:
            The API-specific portion of the URL path
        :returns:
            resource dict
        """

        bulk_list = self.find_bulk(path, **kwargs)
        num_bulk = len(bulk_list)
        if num_bulk == 0:
            msg = "none found"
            raise exceptions.NotFound(msg)
        elif num_bulk > 1:
            msg = "many found"
            raise RuntimeError(msg)
        return bulk_list[0]
Ejemplo n.º 14
0
    def test_delete_multiple_agents_exception(self):
        arglist = [
            self.fake_agents[0].agent_id,
            self.fake_agents[1].agent_id,
            'x-y-z',
        ]
        verifylist = [
            ('id', arglist),
        ]

        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        ret_delete = [None, None, exceptions.NotFound('404')]
        self.agents_mock.delete = mock.Mock(side_effect=ret_delete)

        self.assertRaises(exceptions.CommandError, self.cmd.take_action,
                          parsed_args)
        calls = [
            call(self.fake_agents[0].agent_id),
            call(self.fake_agents[1].agent_id),
        ]
        self.agents_mock.delete.assert_has_calls(calls)
Ejemplo n.º 15
0
    def setUp(self):
        super(TestFlavorUnset, self).setUp()

        self.flavors_mock.find.return_value = self.flavor
        self.flavors_mock.get.side_effect = exceptions.NotFound(None)
        self.cmd = flavor.UnsetFlavor(self.app, None)