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
|
# 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.
#
import uuid
from testtools import TestCase
from trove.common.instance import ServiceStatuses
from trove.datastore import models
from trove.instance.models import InstanceStatus
from trove.instance.models import InstanceServiceStatus
from trove.instance.models import SimpleInstance
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(TestCase):
def setUp(self):
util.init_db()
self.db_info = FakeDBInstance()
self.status = InstanceServiceStatus(
ServiceStatuses.RUNNING)
self.datastore = models.DBDatastore.create(
id=str(uuid.uuid4()),
name='mysql',
default_version_id=self.db_info.datastore_version_id
)
self.version = models.DBDatastoreVersion.create(
id=self.db_info.datastore_version_id,
datastore_id=self.datastore.id,
name='5.5',
manager='mysql',
image_id=str(uuid.uuid4()),
active=1,
packages="mysql-server-5.5"
)
super(BaseInstanceStatusTestCase, self).setUp()
def tearDown(self):
self.datastore.delete()
self.version.delete()
super(BaseInstanceStatusTestCase, self).tearDown()
class InstanceStatusTest(BaseInstanceStatusTestCase):
def test_task_status_error_reports_error(self):
self.db_info.task_status.is_error = True
instance = SimpleInstance('dummy context', self.db_info, self.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.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.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.status)
self.assertEqual(InstanceStatus.RESIZE, instance.status)
def test_task_status_action_deleting_reports_shutdown(self):
self.db_info.task_status.action = "DELETING"
instance = SimpleInstance('dummy context', self.db_info, self.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.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.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.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.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.status)
self.assertEqual(InstanceStatus.RESIZE, instance.status)
def test_service_status_paused_reports_reboot(self):
self.status.set_status(ServiceStatuses.PAUSED)
instance = SimpleInstance('dummy context', self.db_info, self.status)
self.assertEqual(InstanceStatus.REBOOT, instance.status)
def test_service_status_new_reports_build(self):
self.status.set_status(ServiceStatuses.NEW)
instance = SimpleInstance('dummy context', self.db_info, self.status)
self.assertEqual(InstanceStatus.BUILD, instance.status)
def test_service_status_running_reports_active(self):
self.status.set_status(ServiceStatuses.RUNNING)
instance = SimpleInstance('dummy context', self.db_info, self.status)
self.assertEqual(InstanceStatus.ACTIVE, instance.status)
|