Ejemplo n.º 1
0
    def test_map_exceptions_sdk_exception_1(self):
        ksa_exc = _exceptions.ClientException()
        func = mock.Mock(side_effect=ksa_exc)

        os_exc = self.assertRaises(exceptions.SDKException,
                                   session.map_exceptions(func))
        self.assertIsInstance(os_exc, exceptions.SDKException)
        self.assertEqual(ksa_exc, os_exc.cause)
Ejemplo n.º 2
0
class ShellTestWithKeystoneV3Auth(ShellTest):
    # auth environment to use
    auth_env = FAKE_V3_ENV.copy()
    token_url = DEFAULT_V3_AUTH_URL + '/auth/tokens'

    def _assert_auth_plugin_args(self):
        self.assertFalse(self.v2_auth.called)

        body = json.loads(self.v3_auth.last_request.body)
        user = body['auth']['identity']['password']['user']

        self.assertEqual(self.auth_env['OS_USERNAME'], user['name'])
        self.assertEqual(self.auth_env['OS_PASSWORD'], user['password'])
        self.assertEqual(self.auth_env['OS_USER_DOMAIN_NAME'],
                         user['domain']['name'])
        self.assertEqual(self.auth_env['OS_PROJECT_ID'],
                         body['auth']['scope']['project']['id'])

    @mock.patch('glanceclient.v1.client.Client')
    def test_auth_plugin_invocation_with_v1(self, v1_client):
        args = '--os-image-api-version 1 image-list'
        glance_shell = openstack_shell.OpenStackImagesShell()
        glance_shell.main(args.split())
        self.assertEqual(0, self.v3_auth.call_count)

    @mock.patch('glanceclient.v2.client.Client')
    def test_auth_plugin_invocation_with_v2(self, v2_client):
        args = '--os-image-api-version 2 image-list'
        glance_shell = openstack_shell.OpenStackImagesShell()
        glance_shell.main(args.split())
        self.assertEqual(0, self.v3_auth.call_count)

    @mock.patch('keystoneauth1.discover.Discover',
                side_effect=ks_exc.ClientException())
    def test_api_discovery_failed_with_unversioned_auth_url(self,
                                                            discover):
        args = ('--os-image-api-version 2 --os-auth-url %s image-list'
                % DEFAULT_UNVERSIONED_AUTH_URL)
        glance_shell = openstack_shell.OpenStackImagesShell()
        self.assertRaises(exc.CommandError, glance_shell.main, args.split())

    def test_bash_completion(self):
        stdout, stderr = self.shell('--os-image-api-version 2 bash_completion')
        # just check we have some output
        required = [
            '--status',
            'image-create',
            'help',
            '--size']
        for r in required:
            self.assertIn(r, stdout.split())
        avoided = [
            'bash_completion',
            'bash-completion']
        for r in avoided:
            self.assertNotIn(r, stdout.split())
    def test_find_group_with_name(self, mocked_get, mock_list):
        groups = self.app.client_manager.auto_scaling.groups
        mocked_get.side_effect = exceptions.ClientException(0)

        _list = [resource.AutoScalingGroup(None, g) for g in self._groups]
        mock_list.return_value = br.ListWithMeta(_list, None)
        find = groups.find("Woo-Test-1")
        params = dict(scaling_group_name="Woo-Test-1")
        mock_list.assert_called_once_with("/scaling_group",
                                          key="scaling_groups",
                                          params=params)
        self.assertEquals(_list[0], find)
Ejemplo n.º 4
0
    def take_action(self, args):
        client = self.app.client_manager.antiddos
        _antiddos = client.antiddos.find(args.floating_ip)
        # if user pass ip, we should reload antiddos object
        if _antiddos.floating_ip_id != args.floating_ip:
            _antiddos = client.antiddos.get_antiddos(_antiddos.floating_ip_id)

        if 'status' in _antiddos.original and _antiddos.status == 'notConfig':
            raise exceptions.ClientException(
                'You have not config antiddos for this floating ip yet.')
        else:
            if not _antiddos.enable_L7:
                columns = resource.AntiDDos.show_column_names[:-1]
            else:
                columns = resource.AntiDDos.show_column_names
            return columns, _antiddos.get_display_data(columns)
Ejemplo n.º 5
0
    def test_exception(self, mock_get_access):
        user = self.data.user
        form_data = self.get_form_data(user)
        url = reverse('login')

        mock_get_access.side_effect = keystone_exceptions.ClientException(500)

        # GET the page to set the test cookie.
        response = self.client.get(url, form_data)
        self.assertEqual(response.status_code, 200)

        # POST to the page to log in.
        response = self.client.post(url, form_data)
        self.assertTemplateUsed(response, 'auth/login.html')
        self.assertContains(response,
                            ("An error occurred authenticating. Please try "
                             "again later."))

        mock_get_access.assert_called_once_with(IsA(session.Session))
Ejemplo n.º 6
0
    def test_exception(self):
        user = self.data.user
        form_data = self.get_form_data(user)
        exc = keystone_exceptions.ClientException(500)
        self._mock_client_password_auth_failure(user.name, user.password, exc)
        self.mox.ReplayAll()

        url = reverse('login')

        # GET the page to set the test cookie.
        response = self.client.get(url, form_data)
        self.assertEqual(response.status_code, 200)

        # POST to the page to log in.
        response = self.client.post(url, form_data)

        self.assertTemplateUsed(response, 'auth/login.html')
        self.assertContains(response,
                            ("An error occurred authenticating. Please try "
                             "again later."))
Ejemplo n.º 7
0
    def take_action(self, args):
        client = self.app.client_manager.antiddos
        if not args.enable_l7 and args.http_request_rate:
            raise argparse.ArgumentTypeError(
                'argument --http-request-rate only effect '
                'when CC defence protection is enabled')

        floating_ip = client.antiddos.find(args.floating_ip)

        # issue 8, cleaning-pos fixed to 8, app-type fixed to 1
        traffic_pos = pb.AntiDDosParser.get_traffic_pos_id(
            args.maximum_service_traffic)
        http_request_pos = pb.AntiDDosParser.get_http_request_pos_id(
            args.http_request_rate)
        task = client.antiddos.update_antiddos(floating_ip.floating_ip_id,
                                               args.enable_l7, traffic_pos,
                                               http_request_pos, 8, 1)

        if isinstance(task, br.StrWithMeta):
            raise exceptions.ClientException(
                'this floating ip already has the same configuration')
        return 'Request Received, task id: ' + task['task_id']
Ejemplo n.º 8
0
 def test_clientexception_with_no_message(self):
     exc = exceptions.ClientException()
     self.assertEqual(exceptions.ClientException.__name__,
                      exc.message)
Ejemplo n.º 9
0
 def test_clientexception_with_message(self):
     test_message = 'Unittest exception message.'
     exc = exceptions.ClientException(message=test_message)
     self.assertEqual(test_message, exc.message)
 def test_find_group_with_name_no_match(self, mocked_get, mock_list):
     groups = self.app.client_manager.auto_scaling.groups
     mocked_get.side_effect = exceptions.ClientException(0)
     mock_list.return_value = br.ListWithMeta([], None)
     self.assertRaises(exceptions.NotFound, groups.find, "group-name-1")