File: root_on_create.py

package info (click to toggle)
openstack-trove 2014.1.3-8
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 10,752 kB
  • ctags: 6,663
  • sloc: python: 37,317; xml: 1,485; sh: 281; makefile: 49
file content (117 lines) | stat: -rw-r--r-- 4,568 bytes parent folder | download
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
106
107
108
109
110
111
112
113
114
115
116
117
#    Copyright 2013 OpenStack Foundation
#
#    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 proboscis import before_class
from proboscis import after_class
from proboscis import test
from proboscis.asserts import assert_equal
from proboscis.asserts import assert_not_equal
from proboscis.asserts import assert_true

from trove import tests
from trove.common import cfg
from trove.common.utils import poll_until
from trove.tests import util
from trove.tests.api.users import TestUsers
from trove.tests.api.instances import instance_info
from trove.tests.api.databases import TestMysqlAccess

CONF = cfg.CONF
GROUP = "dbaas.api.root.oncreate"


@test(depends_on_classes=[TestMysqlAccess],
      runs_after=[TestUsers],
      groups=[tests.DBAAS_API, GROUP, tests.INSTANCES])
class TestRootOnCreate(object):
    """
    Test 'CONF.root_on_create', which if True, creates the root user upon
    database instance initialization.
    """

    root_enabled_timestamp = 'Never'
    instance_id = None

    def create_instance(self):
        result = self.dbaas.instances.create(
            instance_info.name,
            instance_info.dbaas_flavor_href,
            instance_info.volume,
            instance_info.databases,
            instance_info.users,
            availability_zone="nova",
            datastore=instance_info.dbaas_datastore,
            datastore_version=instance_info.dbaas_datastore_version)
        assert_equal(200, self.dbaas.last_http_code)
        new_id = result.id

        def result_is_active():
            instance = self.dbaas.instances.get(new_id)
            if instance.status == "ACTIVE":
                return True
            else:
                assert_equal("BUILD", instance.status)
        poll_until(result_is_active)
        if 'password' in result._info:
            self.dbaas.root.create(new_id)
        return new_id

    @before_class
    def setUp(self):
        self.orig_conf_value = CONF.get(
            instance_info.dbaas_datastore).root_on_create
        CONF.get(instance_info.dbaas_datastore).root_on_create = True
        self.dbaas = util.create_dbaas_client(instance_info.user)
        self.dbaas_admin = util.create_dbaas_client(instance_info.admin_user)
        self.history = self.dbaas_admin.management.root_enabled_history
        self.enabled = self.dbaas.root.is_root_enabled
        self.instance_id = self.create_instance()

    @after_class
    def tearDown(self):
        CONF.get(instance_info.
                 dbaas_datastore).root_on_create = self.orig_conf_value
        instance = self.dbaas.instances.get(self.instance_id)
        instance.delete()

    @test
    def test_root_on_create(self):
        """Test that root is enabled after instance creation"""
        enabled = self.enabled(self.instance_id).rootEnabled
        assert_equal(200, self.dbaas.last_http_code)
        assert_true(enabled)

    @test(depends_on=[test_root_on_create])
    def test_history_after_root_on_create(self):
        """Test that the timestamp in the root enabled history is set"""
        self.root_enabled_timestamp = self.history(self.instance_id).enabled
        assert_equal(200, self.dbaas.last_http_code)
        assert_not_equal(self.root_enabled_timestamp, 'Never')

    @test(depends_on=[test_history_after_root_on_create])
    def test_reset_root(self):
        """Test that root reset does not alter the timestamp"""
        orig_timestamp = self.root_enabled_timestamp
        self.dbaas.root.create(self.instance_id)
        assert_equal(200, self.dbaas.last_http_code)
        self.root_enabled_timestamp = self.history(self.instance_id).enabled
        assert_equal(200, self.dbaas.last_http_code)
        assert_equal(orig_timestamp, self.root_enabled_timestamp)

    @test(depends_on=[test_reset_root])
    def test_root_still_enabled(self):
        """Test that after root was reset, it's still enabled."""
        enabled = self.enabled(self.instance_id).rootEnabled
        assert_equal(200, self.dbaas.last_http_code)
        assert_true(enabled)