summaryrefslogtreecommitdiff
path: root/tempest/api/compute/floating_ips/test_floating_ips_actions_negative.py
blob: d22d3341bc278b84fc04106ef96cefade746b663 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# 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.

import uuid

from tempest_lib.common.utils import data_utils
from tempest_lib import exceptions as lib_exc

from tempest.api.compute.floating_ips import base
from tempest import config
from tempest import test

CONF = config.CONF


class FloatingIPsNegativeTestJSON(base.BaseFloatingIPsTest):
    server_id = None

    @classmethod
    def setup_clients(cls):
        super(FloatingIPsNegativeTestJSON, cls).setup_clients()
        cls.client = cls.floating_ips_client

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

        # Server creation
        server = cls.create_test_server(wait_until='ACTIVE')
        cls.server_id = server['id']
        # Generating a nonexistent floatingIP id
        cls.floating_ip_ids = []
        body = cls.client.list_floating_ips()
        for i in range(len(body)):
            cls.floating_ip_ids.append(body[i]['id'])
        while True:
            cls.non_exist_id = data_utils.rand_int_id(start=999)
            if CONF.service_available.neutron:
                cls.non_exist_id = str(uuid.uuid4())
            if cls.non_exist_id not in cls.floating_ip_ids:
                break

    @test.attr(type=['negative'])
    @test.idempotent_id('6e0f059b-e4dd-48fb-8207-06e3bba5b074')
    @test.services('network')
    def test_allocate_floating_ip_from_nonexistent_pool(self):
        # Negative test:Allocation of a new floating IP from a nonexistent_pool
        # to a project should fail
        self.assertRaises(lib_exc.NotFound,
                          self.client.create_floating_ip,
                          "non_exist_pool")

    @test.attr(type=['negative'])
    @test.idempotent_id('ae1c55a8-552b-44d4-bfb6-2a115a15d0ba')
    @test.services('network')
    def test_delete_nonexistent_floating_ip(self):
        # Negative test:Deletion of a nonexistent floating IP
        # from project should fail

        # Deleting the non existent floating IP
        self.assertRaises(lib_exc.NotFound, self.client.delete_floating_ip,
                          self.non_exist_id)

    @test.attr(type=['negative'])
    @test.idempotent_id('595fa616-1a71-4670-9614-46564ac49a4c')
    @test.services('network')
    def test_associate_nonexistent_floating_ip(self):
        # Negative test:Association of a non existent floating IP
        # to specific server should fail
        # Associating non existent floating IP
        self.assertRaises(lib_exc.NotFound,
                          self.client.associate_floating_ip_to_server,
                          "0.0.0.0", self.server_id)

    @test.attr(type=['negative'])
    @test.idempotent_id('0a081a66-e568-4e6b-aa62-9587a876dca8')
    @test.services('network')
    def test_dissociate_nonexistent_floating_ip(self):
        # Negative test:Dissociation of a non existent floating IP should fail
        # Dissociating non existent floating IP
        self.assertRaises(lib_exc.NotFound,
                          self.client.disassociate_floating_ip_from_server,
                          "0.0.0.0", self.server_id)

    @test.attr(type=['negative'])
    @test.idempotent_id('804b4fcb-bbf5-412f-925d-896672b61eb3')
    @test.services('network')
    def test_associate_ip_to_server_without_passing_floating_ip(self):
        # Negative test:Association of empty floating IP to specific server
        # should raise NotFound or BadRequest(In case of Nova V2.1) exception.
        self.assertRaises((lib_exc.NotFound, lib_exc.BadRequest),
                          self.client.associate_floating_ip_to_server,
                          '', self.server_id)