summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--reddwarf/guestagent/manager.py2
-rw-r--r--reddwarf/tests/guestagent/__init__.py13
-rw-r--r--reddwarf/tests/unittests/guestagent/test_manager.py (renamed from reddwarf/tests/guestagent/test_manager.py)31
-rw-r--r--reddwarf/tests/unittests/guestagent/test_models.py (renamed from reddwarf/tests/guestagent/test_models.py)9
-rw-r--r--reddwarf/tests/unittests/guestagent/test_query.py (renamed from reddwarf/tests/guestagent/test_query.py)2
-rw-r--r--reddwarf/tests/unittests/guestagent/test_service.py (renamed from reddwarf/tests/guestagent/test_service.py)2
-rw-r--r--reddwarf/tests/unittests/guestagent/test_volume.py180
-rw-r--r--run_tests.py4
8 files changed, 200 insertions, 43 deletions
diff --git a/reddwarf/guestagent/manager.py b/reddwarf/guestagent/manager.py
index 57c2e369..e1fae542 100644
--- a/reddwarf/guestagent/manager.py
+++ b/reddwarf/guestagent/manager.py
@@ -2,7 +2,7 @@ from reddwarf.guestagent import dbaas
from reddwarf.guestagent import volume
from reddwarf.openstack.common import log as logging
from reddwarf.openstack.common import periodic_task
-
+from reddwarf.openstack.common.gettextutils import _
LOG = logging.getLogger(__name__)
MYSQL_BASE_DIR = "/var/lib/mysql"
diff --git a/reddwarf/tests/guestagent/__init__.py b/reddwarf/tests/guestagent/__init__.py
deleted file mode 100644
index 40d014dd..00000000
--- a/reddwarf/tests/guestagent/__init__.py
+++ /dev/null
@@ -1,13 +0,0 @@
-# Copyright 2011 OpenStack LLC
-#
-# 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.
diff --git a/reddwarf/tests/guestagent/test_manager.py b/reddwarf/tests/unittests/guestagent/test_manager.py
index 8ba1cf8c..fb7308f3 100644
--- a/reddwarf/tests/guestagent/test_manager.py
+++ b/reddwarf/tests/unittests/guestagent/test_manager.py
@@ -18,10 +18,7 @@ from reddwarf.guestagent import volume
import testtools
from mock import Mock, MagicMock
-from proboscis import test
-
-@test(groups=["dbaas.guestagent.dbaas"])
class GuestAgentManagerTest(testtools.TestCase):
def setUp(self):
@@ -93,9 +90,6 @@ class GuestAgentManagerTest(testtools.TestCase):
def test_prepare_device_path_false(self):
self._prepare_dynamic(has_device_path=False)
- def test_prepare_mysql_installed(self):
- self._prepare_dynamic(has_device_path=False)
-
def test_prepare_mysql_not_installed(self):
self._prepare_dynamic(is_mysql_installed=False)
@@ -113,13 +107,13 @@ class GuestAgentManagerTest(testtools.TestCase):
self._setUp_MySqlAppStatus_get()
dbaas.MySqlAppStatus.begin_mysql_install = MagicMock()
+ origin_format = volume.VolumeDevice.format
volume.VolumeDevice.format = MagicMock()
- if is_mysql_installed:
- self._prepare_mysql_is_installed()
- else:
- self._prepare_mysql_is_not_installed()
+ origin_is_installed, origin_stop_mysql, origin_migrate_data =\
+ self._prepare_mysql_is_installed(is_mysql_installed)
+ origin_mount = volume.VolumeDevice.mount
volume.VolumeDevice.mount = MagicMock()
dbaas.MySqlApp.start_mysql = MagicMock()
@@ -148,13 +142,20 @@ class GuestAgentManagerTest(testtools.TestCase):
self.assertEqual(1, Manager.create_database.call_count)
self.assertEqual(1, Manager.create_user.call_count)
- def _prepare_mysql_is_installed(self):
- dbaas.MySqlApp.is_installed = MagicMock(return_value=True)
+ volume.VolumeDevice.format = origin_format
+ volume.VolumeDevice.migrate_data = origin_migrate_data
+ dbaas.MySqlApp.is_installed = origin_is_installed
+ dbaas.MySqlApp.stop_mysql = origin_stop_mysql
+ volume.VolumeDevice.mount = origin_mount
+
+ def _prepare_mysql_is_installed(self, is_installed=True):
+ origin_is_installed = dbaas.MySqlApp.is_installed
+ origin_stop_mysql = dbaas.MySqlApp.stop_mysql
+ origin_migrate_data = volume.VolumeDevice.migrate_data
+ dbaas.MySqlApp.is_installed = MagicMock(return_value=is_installed)
dbaas.MySqlApp.stop_mysql = MagicMock()
volume.VolumeDevice.migrate_data = MagicMock()
-
- def _prepare_mysql_is_not_installed(self):
- dbaas.MySqlApp.is_installed = MagicMock(return_value=False)
+ return origin_is_installed, origin_stop_mysql, origin_migrate_data
def test_restart(self):
self._setUp_MySqlAppStatus_get()
diff --git a/reddwarf/tests/guestagent/test_models.py b/reddwarf/tests/unittests/guestagent/test_models.py
index 176e6a04..b5fef917 100644
--- a/reddwarf/tests/guestagent/test_models.py
+++ b/reddwarf/tests/unittests/guestagent/test_models.py
@@ -16,14 +16,11 @@ import testtools
from mock import Mock, MagicMock
from reddwarf.guestagent import models
from reddwarf.common import utils
-from reddwarf.db import sqlalchemy
+from reddwarf.db.sqlalchemy import api as dbapi
from reddwarf.db import models as dbmodels
-from proboscis import test
-
from datetime import datetime
-@test(groups=["dbaas.guestagent.dbaas"])
class AgentHeartBeatTest(testtools.TestCase):
def setUp(self):
super(AgentHeartBeatTest, self).setUp()
@@ -33,7 +30,7 @@ class AgentHeartBeatTest(testtools.TestCase):
def test_create(self):
utils.generate_uuid = Mock()
- sqlalchemy.api.save = MagicMock(
+ dbapi.save = MagicMock(
return_value=dbmodels.DatabaseModelBase)
dbmodels.DatabaseModelBase.is_valid = Mock(return_value=True)
models.AgentHeartBeat.create()
@@ -46,7 +43,7 @@ class AgentHeartBeatTest(testtools.TestCase):
dbmodels.DatabaseModelBase = Mock
dbmodels.get_db_api = MagicMock(
return_value=dbmodels.DatabaseModelBase)
- sqlalchemy.api.save = Mock()
+ dbapi.save = Mock()
dbmodels.DatabaseModelBase.is_valid = Mock(return_value=True)
self.heartBeat = models.AgentHeartBeat()
self.heartBeat.save()
diff --git a/reddwarf/tests/guestagent/test_query.py b/reddwarf/tests/unittests/guestagent/test_query.py
index cd02342c..be0a91d3 100644
--- a/reddwarf/tests/guestagent/test_query.py
+++ b/reddwarf/tests/unittests/guestagent/test_query.py
@@ -14,10 +14,8 @@
import testtools
from reddwarf.guestagent import query
-from proboscis import test
-@test(groups=["dbaas.guestagent.dbaas"])
class QueryTest(testtools.TestCase):
def setUp(self):
super(QueryTest, self).setUp()
diff --git a/reddwarf/tests/guestagent/test_service.py b/reddwarf/tests/unittests/guestagent/test_service.py
index 335bfa57..1b24c03b 100644
--- a/reddwarf/tests/guestagent/test_service.py
+++ b/reddwarf/tests/unittests/guestagent/test_service.py
@@ -15,10 +15,8 @@
import testtools
from mock import Mock, MagicMock
from reddwarf.guestagent import service
-from proboscis import test
-@test(groups=["dbaas.guestagent.dbaas"])
class ServiceTest(testtools.TestCase):
def setUp(self):
super(ServiceTest, self).setUp()
diff --git a/reddwarf/tests/unittests/guestagent/test_volume.py b/reddwarf/tests/unittests/guestagent/test_volume.py
new file mode 100644
index 00000000..dffd5a9c
--- /dev/null
+++ b/reddwarf/tests/unittests/guestagent/test_volume.py
@@ -0,0 +1,180 @@
+# Copyright 2012 OpenStack LLC
+#
+# 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 os
+import testtools
+import pexpect
+from mock import Mock, MagicMock
+from reddwarf.guestagent import volume
+from reddwarf.common import utils
+
+
+def _setUp_fake_spawn(return_val=0):
+ fake_spawn = pexpect.spawn('echo')
+ fake_spawn.expect = Mock(return_value=return_val)
+ pexpect.spawn = Mock(return_value=fake_spawn)
+ return fake_spawn
+
+
+class VolumeDeviceTest(testtools.TestCase):
+
+ def setUp(self):
+ super(VolumeDeviceTest, self).setUp()
+ self.volumeDevice = volume.VolumeDevice('/dev/vdb')
+
+ def tearDown(self):
+ super(VolumeDeviceTest, self).tearDown()
+
+ def test_migrate_data(self):
+ origin_execute = utils.execute
+ utils.execute = Mock()
+
+ origin_tmp_mount = self.volumeDevice._tmp_mount
+ origin_unmount = self.volumeDevice.unmount
+ self.volumeDevice._tmp_mount = MagicMock()
+ self.volumeDevice.unmount = MagicMock()
+ self.volumeDevice.migrate_data('/')
+ self.assertEqual(2, utils.execute.call_count)
+ self.assertEqual(1, self.volumeDevice._tmp_mount.call_count)
+ self.assertEqual(1, self.volumeDevice.unmount.call_count)
+ utils.execute = origin_execute
+ self.volumeDevice._tmp_mount = origin_tmp_mount
+ self.volumeDevice.unmount = origin_unmount
+
+ def test__check_device_exists(self):
+ origin_execute = utils.execute
+ utils.execute = Mock()
+ self.volumeDevice._check_device_exists()
+ self.assertEqual(1, utils.execute.call_count)
+ utils.execute = origin_execute
+
+ def test__check_format(self):
+ fake_spawn = _setUp_fake_spawn()
+
+ self.volumeDevice._check_format()
+ self.assertEqual(1, fake_spawn.expect.call_count)
+
+ def test__check_format_2(self):
+ fake_spawn = _setUp_fake_spawn(return_val=1)
+ self.assertRaises(IOError, self.volumeDevice._check_format)
+
+ def test__format(self):
+ fake_spawn = _setUp_fake_spawn()
+
+ self.volumeDevice._format()
+
+ self.assertEqual(1, fake_spawn.expect.call_count)
+ self.assertEqual(1, pexpect.spawn.call_count)
+
+ def test_format(self):
+ origin_check_device_exists = self.volumeDevice._check_device_exists
+ origin_format = self.volumeDevice._format
+ origin_check_format = self.volumeDevice._check_format
+ self.volumeDevice._check_device_exists = MagicMock()
+ self.volumeDevice._check_format = MagicMock()
+ self.volumeDevice._format = MagicMock()
+
+ self.volumeDevice.format()
+ self.assertEqual(1, self.volumeDevice._check_device_exists.call_count)
+ self.assertEqual(1, self.volumeDevice._format.call_count)
+ self.assertEqual(1, self.volumeDevice._check_format.call_count)
+
+ self.volumeDevice._check_device_exists = origin_check_device_exists
+ self.volumeDevice._format = origin_format
+ self.volumeDevice._check_format = origin_check_format
+
+ def test_mount(self):
+ origin_ = volume.VolumeMountPoint.mount
+ volume.VolumeMountPoint.mount = Mock()
+ origin_write_to_fstab = volume.VolumeMountPoint.write_to_fstab
+ volume.VolumeMountPoint.write_to_fstab = Mock()
+
+ self.volumeDevice.mount(Mock)
+ self.assertEqual(1, volume.VolumeMountPoint.mount.call_count)
+ self.assertEqual(1, volume.VolumeMountPoint.write_to_fstab.call_count)
+ volume.VolumeMountPoint.mount = origin_
+ volume.VolumeMountPoint.write_to_fstab = origin_write_to_fstab
+
+ def test_resize_fs(self):
+ origin_check_device_exists = self.volumeDevice._check_device_exists
+ origin_execute = utils.execute
+ utils.execute = Mock()
+ self.volumeDevice._check_device_exists = MagicMock()
+
+ self.volumeDevice.resize_fs()
+
+ self.assertEqual(1, self.volumeDevice._check_device_exists.call_count)
+ self.assertEqual(1, utils.execute.call_count)
+ self.volumeDevice._check_device_exists = origin_check_device_exists
+ utils.execute = origin_execute
+
+ def test__tmp_mount(self):
+ origin_ = volume.VolumeMountPoint.mount
+ volume.VolumeMountPoint.mount = Mock()
+
+ self.volumeDevice._tmp_mount(Mock)
+ self.assertEqual(1, volume.VolumeMountPoint.mount.call_count)
+ volume.VolumeMountPoint.mount = origin_
+
+ def test_unmount_positive(self):
+ self._test_unmount()
+
+ def test_unmount_negative(self):
+ self._test_unmount(False)
+
+ def _test_unmount(self, positive=True):
+ origin_ = os.path.exists
+ os.path.exists = MagicMock(return_value=positive)
+ fake_spawn = _setUp_fake_spawn()
+
+ self.volumeDevice.unmount()
+ COUNT = 1
+ if not positive:
+ COUNT = 0
+ self.assertEqual(COUNT, fake_spawn.expect.call_count)
+ os.path.exists = origin_
+
+
+class VolumeMountPointTest(testtools.TestCase):
+ def setUp(self):
+ super(VolumeMountPointTest, self).setUp()
+ self.volumeMountPoint = volume.VolumeMountPoint('/mnt/device',
+ '/dev/vdb')
+
+ def tearDown(self):
+ super(VolumeMountPointTest, self).tearDown()
+
+ def test_mount(self):
+ origin_ = os.path.exists
+ os.path.exists = MagicMock(return_value=False)
+ fake_spawn = _setUp_fake_spawn()
+
+ os.makedirs = MagicMock()
+
+ self.volumeMountPoint.mount()
+
+ self.assertEqual(1, os.path.exists.call_count)
+ self.assertEqual(1, os.makedirs.call_count)
+ self.assertEqual(1, fake_spawn.expect.call_count)
+
+ os.path.exists = origin_
+
+ def test_write_to_fstab(self):
+ origin_execute = utils.execute
+ utils.execute = Mock()
+ open = MagicMock()
+
+ self.volumeMountPoint.write_to_fstab()
+
+ self.assertEqual(5, utils.execute.call_count)
+ utils.execute = origin_execute
diff --git a/run_tests.py b/run_tests.py
index b4da1311..2e1e7bba 100644
--- a/run_tests.py
+++ b/run_tests.py
@@ -124,9 +124,5 @@ if __name__=="__main__":
from reddwarf.tests.api.mgmt import admin_required
from reddwarf.tests.api.mgmt import instances
from reddwarf.tests.api.mgmt import storage
- from reddwarf.tests.guestagent import test_manager
- from reddwarf.tests.guestagent import test_service
- from reddwarf.tests.guestagent import test_query
- from reddwarf.tests.guestagent import test_models
proboscis.TestProgram().run_and_exit()