<commit_before># Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from tempest.api.compute import base
from tempest.common import waiters
from tempest.lib import exceptions as lib_exc
from tempest import test


class ListServersNegativeTestJSON(base.BaseV2ComputeTest):

    @classmethod
    def setup_clients(cls):
        super(ListServersNegativeTestJSON, cls).setup_clients()
        cls.client = cls.servers_client

    @classmethod
    def resource_setup(cls):
        super(ListServersNegativeTestJSON, cls).resource_setup()

        # The following servers are created for use
        # by the test methods in this class. These
        # servers are cleaned up automatically in the
        # tearDownClass method of the super-class.
        cls.existing_fixtures = []
        cls.deleted_fixtures = []
        for x in range(2):
            srv = cls.create_test_server(wait_until='ACTIVE')
            cls.existing_fixtures.append(srv)

        srv = cls.create_test_server()
        cls.client.delete_server(srv['id'])
        # We ignore errors on termination because the server may
        # be put into ERROR status on a quick spawn, then delete,
        # as the compute node expects the instance local status
        # to be spawning, not deleted. See LP Bug#1061167
        waiters.wait_for_server_termination(cls.client, srv['id'],
                                            ignore_error=True)
        cls.deleted_fixtures.append(srv)

    @test.attr(type=['negative'])
    @test.idempotent_id('24a26f1a-1ddc-4eea-b0d7-a90cc874ad8f')
    def test_list_servers_with_a_deleted_server(self):
        # Verify deleted servers do not show by default in list servers
        # List servers and verify server not returned
        body = self.client.list_servers()
        servers = body['servers']
        deleted_ids = [s['id'] for s in self.deleted_fixtures]
        actual = [srv for srv in servers
                  if srv['id'] in deleted_ids]
        self.assertEqual([], actual)

    @test.attr(type=['negative'])
    @test.idempotent_id('ff01387d-c7ad-47b4-ae9e-64fa214638fe')
    def test_list_servers_by_non_existing_image(self):
        # Listing servers for a non existing image returns empty list
        non_existing_image = '1234abcd-zzz0-aaa9-ppp3-0987654abcde'
        body = self.client.list_servers(image=non_existing_image)
        servers = body['servers']
        self.assertEqual([], servers)

    @test.attr(type=['negative'])
    @test.idempotent_id('5913660b-223b-44d4-a651-a0fbfd44ca75')
    def test_list_servers_by_non_existing_flavor(self):
        # Listing servers by non existing flavor returns empty list
        non_existing_flavor = 1234
        body = self.client.list_servers(flavor=non_existing_flavor)
        servers = body['servers']
        self.assertEqual([], servers)

    @test.attr(type=['negative'])
    @test.idempotent_id('e2c77c4a-000a-4af3-a0bd-629a328bde7c')
    def test_list_servers_by_non_existing_server_name(self):
        # Listing servers for a non existent server name returns empty list
        non_existing_name = 'junk_server_1234'
        body = self.client.list_servers(name=non_existing_name)
        servers = body['servers']
        self.assertEqual([], servers)

    @test.attr(type=['negative'])
    @test.idempotent_id('fcdf192d-0f74-4d89-911f-1ec002b822c4')
    def test_list_servers_status_non_existing(self):
        # Return an empty list when invalid status is specified
        non_existing_status = 'BALONEY'
        body = self.client.list_servers(status=non_existing_status)
        servers = body['servers']
        self.assertEqual([], servers)

    @test.idempotent_id('12c80a9f-2dec-480e-882b-98ba15757659')
    def test_list_servers_by_limits(self):
        # List servers by specifying limits<commit_msg>Use names containing "non-existing" as non-existing resource names<commit_after># Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from tempest.api.compute import base
from tempest.common import waiters
from tempest.lib import exceptions as lib_exc
from tempest import test


class ListServersNegativeTestJSON(base.BaseV2ComputeTest):

    @classmethod
    def setup_clients(cls):
        super(ListServersNegativeTestJSON, cls).setup_clients()
        cls.client = cls.servers_client

    @classmethod
    def resource_setup(cls):
        super(ListServersNegativeTestJSON, cls).resource_setup()

        # The following servers are created for use
        # by the test methods in this class. These
        # servers are cleaned up automatically in the
        # tearDownClass method of the super-class.
        cls.existing_fixtures = []
        cls.deleted_fixtures = []
        for x in range(2):
            srv = cls.create_test_server(wait_until='ACTIVE')
            cls.existing_fixtures.append(srv)

        srv = cls.create_test_server()
        cls.client.delete_server(srv['id'])
        # We ignore errors on termination because the server may
        # be put into ERROR status on a quick spawn, then delete,
        # as the compute node expects the instance local status
        # to be spawning, not deleted. See LP Bug#1061167
        waiters.wait_for_server_termination(cls.client, srv['id'],
                                            ignore_error=True)
        cls.deleted_fixtures.append(srv)

    @test.attr(type=['negative'])
    @test.idempotent_id('24a26f1a-1ddc-4eea-b0d7-a90cc874ad8f')
    def test_list_servers_with_a_deleted_server(self):
        # Verify deleted servers do not show by default in list servers
        # List servers and verify server not returned
        body = self.client.list_servers()
        servers = body['servers']
        deleted_ids = [s['id'] for s in self.deleted_fixtures]
        actual = [srv for srv in servers
                  if srv['id'] in deleted_ids]
        self.assertEqual([], actual)

    @test.attr(type=['negative'])
    @test.idempotent_id('ff01387d-c7ad-47b4-ae9e-64fa214638fe')
    def test_list_servers_by_non_existing_image(self):
        # Listing servers for a non existing image returns empty list
        body = self.client.list_servers(image='non_existing_image')
        servers = body['servers']
        self.assertEqual([], servers)

    @test.attr(type=['negative'])
    @test.idempotent_id('5913660b-223b-44d4-a651-a0fbfd44ca75')
    def test_list_servers_by_non_existing_flavor(self):
        # Listing servers by non existing flavor returns empty list
        body = self.client.list_servers(flavor='non_existing_flavor')
        servers = body['servers']
        self.assertEqual([], servers)

    @test.attr(type=['negative'])
    @test.idempotent_id('e2c77c4a-000a-4af3-a0bd-629a328bde7c')
    def test_list_servers_by_non_existing_server_name(self):
        # Listing servers for a non existent server name returns empty list
        body = self.client.list_servers(name='non_existing_server_name')
        servers = body['servers']
        self.assertEqual([], servers)

    @test.attr(type=['negative'])
    @test.idempotent_id('fcdf192d-0f74-4d89-911f-1ec002b822c4')
    def test_list_servers_status_non_existing(self):
        # Return an empty list when invalid status is specified
        body = self.client.list_servers(status='non_existing_status')
        servers = body['servers']
        self.assertEqual([], servers)

    @test.idempotent_id('12c80a9f-2dec-480e-882b-98ba15757659')
    def test_list_servers_by_limits(self):
        # List servers by specifying limits
{'fraction_non_alphanumeric': 0.08782066096602727, 'fraction_numerical': 0.03258608735844696, 'mean_word_length': 3.1451149425287355, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2139659', 'n_tokens_mistral': 2723, 'n_tokens_neox': 2603, 'n_words': 672}