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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
# Copyright 2013 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 unittest import mock
import uuid
from trove.datastore import models
from trove.instance.models import InstanceServiceStatus
from trove.instance.models import InstanceStatus
from trove.instance.models import SimpleInstance
from trove.instance.service_status import ServiceStatuses
from trove.instance.tasks import InstanceTasks
from trove.tests.unittests import trove_testtools
from trove.tests.unittests.util import util
class FakeInstanceTask(object):
def __init__(self):
self.is_error = False
self.action = None
class FakeDBInstance(object):
def __init__(self):
self.id = str(uuid.uuid4())
self.deleted = False
self.datastore_version_id = str(uuid.uuid4())
self.server_status = "ACTIVE"
self.task_status = FakeInstanceTask()
class BaseInstanceStatusTestCase(trove_testtools.TestCase):
@classmethod
def setUpClass(cls):
cls.db_info = FakeDBInstance()
cls.datastore = models.DBDatastore.create(
id=str(uuid.uuid4()),
name='mysql' + str(uuid.uuid4()),
default_version_id=cls.db_info.datastore_version_id
)
cls.version = models.DBDatastoreVersion.create(
id=cls.db_info.datastore_version_id,
datastore_id=cls.datastore.id,
name='5.7' + str(uuid.uuid4()),
manager='mysql',
image_id=str(uuid.uuid4()),
registry_ext="registry_ext",
repl_strategy="repl_strategy",
active=1,
packages="mysql-server-5.7"
)
super(BaseInstanceStatusTestCase, cls).setUpClass()
@classmethod
def tearDownClass(cls):
util.cleanup_db()
super(BaseInstanceStatusTestCase, cls).tearDownClass()
class InstanceStatusTest(BaseInstanceStatusTestCase):
def setUp(self):
self.db_info.task_status = FakeInstanceTask()
self.db_info.server_status = "ACTIVE"
self.ds_status = InstanceServiceStatus(ServiceStatuses.HEALTHY)
super(InstanceStatusTest, self).setUp()
def test_task_status_error_reports_error(self):
self.db_info.task_status.is_error = True
instance = SimpleInstance('dummy context', self.db_info,
self.ds_status)
self.assertEqual(InstanceStatus.ERROR, instance.status)
def test_task_status_action_building_reports_build(self):
self.db_info.task_status.action = "BUILDING"
instance = SimpleInstance('dummy context', self.db_info,
self.ds_status)
self.assertEqual(InstanceStatus.BUILD, instance.status)
def test_task_status_action_rebooting_reports_reboot(self):
self.db_info.task_status.action = "REBOOTING"
instance = SimpleInstance('dummy context', self.db_info,
self.ds_status)
self.assertEqual(InstanceStatus.REBOOT, instance.status)
def test_task_status_action_resizing_reports_resize(self):
self.db_info.task_status.action = "RESIZING"
instance = SimpleInstance('dummy context', self.db_info,
self.ds_status)
self.assertEqual(InstanceStatus.RESIZE, instance.status)
def test_task_deleting_server_active(self):
self.db_info.task_status.action = "DELETING"
instance = SimpleInstance('dummy context', self.db_info,
self.ds_status)
self.assertEqual(InstanceStatus.SHUTDOWN, instance.status)
def test_nova_server_build_reports_build(self):
self.db_info.server_status = "BUILD"
instance = SimpleInstance('dummy context', self.db_info,
self.ds_status)
self.assertEqual(InstanceStatus.BUILD, instance.status)
def test_nova_server_error_reports_error(self):
self.db_info.server_status = "ERROR"
instance = SimpleInstance('dummy context', self.db_info,
self.ds_status)
self.assertEqual(InstanceStatus.ERROR, instance.status)
def test_nova_server_reboot_reports_reboot(self):
self.db_info.server_status = "REBOOT"
instance = SimpleInstance('dummy context', self.db_info,
self.ds_status)
self.assertEqual(InstanceStatus.REBOOT, instance.status)
def test_nova_server_resize_reports_resize(self):
self.db_info.server_status = "RESIZE"
instance = SimpleInstance('dummy context', self.db_info,
self.ds_status)
self.assertEqual(InstanceStatus.RESIZE, instance.status)
def test_nova_server_verify_resize_reports_resize(self):
self.db_info.server_status = "VERIFY_RESIZE"
instance = SimpleInstance('dummy context', self.db_info,
self.ds_status)
self.assertEqual(InstanceStatus.RESIZE, instance.status)
def test_operating_status_healthy(self):
self.db_info.task_status = InstanceTasks.NONE
instance = SimpleInstance(mock.MagicMock(), self.db_info,
self.ds_status)
self.assertEqual(repr(ServiceStatuses.HEALTHY),
instance.operating_status)
def test_operating_status_task_not_none(self):
self.db_info.task_status = InstanceTasks.RESIZING
instance = SimpleInstance(mock.MagicMock(), self.db_info,
self.ds_status)
self.assertEqual("",
instance.operating_status)
|