Permalink
Browse files

More tests. Now with 50% test coverage!

  • Loading branch information...
1 parent 93182d6 commit fc7a4e7e15954674fa21863ae72fcc5262f50e2e @oldpatricka oldpatricka committed Jul 13, 2011
@@ -252,9 +252,11 @@ def _find_controllers_from_svc(self, service_type):
"""
svc = get_cloudinitd_service(self.cloudinitd, service_type)
allkeys = svc.get_keys_from_bag()
+ print allkeys
controllers = []
for key in allkeys:
if key.startswith(self.controller_prefix):
+ print "Whoop"
controllers.append(svc.get_attr_from_bag(key))
return controllers
@@ -20,7 +20,7 @@ def __init__(self, remote_svc_adapter=None, runlogs=None):
self.persistence = FakePersistence()
self.runlogs = runlogs
-def build_fake_scp_command_str(target, real_scp_command_str):
+def make_fake_scp_command_str(target, real_scp_command_str):
def fake_scp_command_str(target, c, vm, cloudinitd):
scpcmd = real_scp_command_str(c, vm, cloudinitd)
scpcmd = "echo %s" % scpcmd
@@ -13,7 +13,7 @@
from mocks.common import FakeCommon
from mocks.modules import FakeModules
-from mocks.modules import build_fake_scp_command_str
+from mocks.modules import make_fake_scp_command_str
from mocks.remote_svc_adapter import FakeRemoteSvcAdapter
class TestCloudinitdLoad:
@@ -48,7 +48,7 @@ def setup(self):
runlogs = DefaultRunlogs(self.params, self.common)
runlogs.validate()
self.modules.runlogs = runlogs
- new_get_scp = build_fake_scp_command_str(runlogs, runlogs.get_scp_command_str)
+ new_get_scp = make_fake_scp_command_str(runlogs, runlogs.get_scp_command_str)
self.modules.runlogs.get_scp_command_str = types.MethodType(new_get_scp, self.modules.runlogs)
self.test_dir = os.path.dirname(__file__)
@@ -1,6 +1,9 @@
-import nose.tools
import os
+import re
+import types
+import shutil
import tempfile
+import nose.tools
import ConfigParser
import epumgmt.defaults.svc_adapter
@@ -9,7 +12,8 @@
from epumgmt.api.exceptions import *
from epumgmt.api import RunVM
-from epumgmt.defaults.parameters import DefaultParameters
+from epumgmt.defaults import DefaultParameters
+from epumgmt.defaults import DefaultRunlogs
from mocks.common import FakeCommon
from mocks.modules import FakeModules
@@ -42,6 +46,11 @@ def setup(self):
self.run_name = "TESTRUN"
self.config = ConfigParser.RawConfigParser()
+ self.config.add_section("events")
+ self.runlogdir = tempfile.mkdtemp()
+ self.config.set("events", "runlogdir", self.runlogdir)
+ self.vmlogdir = tempfile.mkdtemp()
+ self.config.set("events", "vmlogdir", self.vmlogdir)
self.config.add_section("svcadapter")
self.config.set("svcadapter", "controller_prefix", "controller")
self.config.set("svcadapter", "homedir", "app")
@@ -53,15 +62,30 @@ def setup(self):
self.p.optdict = self.optdict
+
self.m = FakeModules()
self.c = FakeCommon()
self.svc_adapter = DefaultRemoteSvcAdapter(self.p, self.c)
+ runlogs = DefaultRunlogs(self.p, self.c)
+ self.m.runlogs = runlogs
+ runlogs.validate()
+
+ new_run_one_cmd = make_fake_run_one_cmd(self.svc_adapter,
+ self.svc_adapter._run_one_cmd)
+ self.svc_adapter._run_one_cmd = types.MethodType(new_run_one_cmd,
+ self.svc_adapter)
+
self.test_dir = os.path.dirname(__file__)
self.test_db_dir = tempfile.mkdtemp()
self.test_cd_config = os.path.join(self.test_dir, "configs/main.conf")
self.cloudinitd = CloudInitD(self.test_db_dir, self.test_cd_config, self.run_name)
+ def teardown(self):
+
+ shutil.rmtree(self.test_db_dir)
+ shutil.rmtree(self.runlogdir)
+ shutil.rmtree(self.vmlogdir)
def test_worker_state(self):
@@ -103,3 +127,55 @@ def test_worker_state(self):
assert raised_incompatible_env
+ provisioner.hostname = "some.fake.hostname"
+ provisioner.service_type = "provisioner"
+ provisioner.runlogdir = self.runlogdir
+ self.svc_adapter.provisioner._svc._s.hostname = provisioner.hostname
+ try:
+ self.svc_adapter.worker_state(controllers, provisioner)
+ except UnexpectedError as e:
+ print e.msg
+ assert "Expecting to find the state query result here" in e.msg
+
+ ssh_commands = [message for (level, message)
+ in self.c.log.transcript
+ if level == "DEBUG"
+ and "command = 'echo ssh" in message]
+ ssh_command = ssh_commands[0]
+
+ # Make sure epu-state called for provisioner
+ assert re.match(".*ssh.*%s.*epu-state" % provisioner.hostname, ssh_command)
+ # Make sure we query both controllers
+ assert re.match(".*epu-state.*%s" % controllers[0], ssh_command)
+ assert re.match(".*epu-state.*%s" % controllers[1], ssh_command)
+
+
+ def test_reconcile_relative_conf(self):
+
+ absolute_dir = "/path/to/conf"
+ relative_dir = "path/to/conf"
+ user = "thetestuser"
+
+ self.svc_adapter.initialize(self.m, self.run_name, self.cloudinitd)
+ got_path = self.svc_adapter._reconcile_relative_conf(absolute_dir, "", "")
+
+ assert got_path == absolute_dir
+
+ try:
+ got_path = self.svc_adapter._reconcile_relative_conf(relative_dir, "", "")
+ raised_incompatible_env = False
+ except IncompatibleEnvironment:
+ raised_incompatible_env = True
+
+ assert raised_incompatible_env
+
+ got_path = self.svc_adapter._reconcile_relative_conf(relative_dir, user, "")
+ assert got_path == "/home/%s/%s" % (user, relative_dir)
+
+
+def make_fake_run_one_cmd(target, real_run_one_cmd):
+ def fake_run_one_cmd(target, cmd):
+ cmd = "echo %s" % cmd
+ return real_run_one_cmd(cmd)
+
+ return fake_run_one_cmd
@@ -15,7 +15,7 @@
from mocks.common import FakeCommon
from mocks.modules import FakeModules
-from mocks.modules import build_fake_scp_command_str
+from mocks.modules import make_fake_scp_command_str
from mocks.remote_svc_adapter import FakeRemoteSvcAdapter
from mocks.event import Event
@@ -52,7 +52,7 @@ def setup(self):
runlogs = DefaultRunlogs(self.params, self.common)
runlogs.validate()
self.modules.runlogs = runlogs
- new_get_scp = build_fake_scp_command_str(runlogs, runlogs.get_scp_command_str)
+ new_get_scp = make_fake_scp_command_str(runlogs, runlogs.get_scp_command_str)
self.modules.runlogs.get_scp_command_str = types.MethodType(new_get_scp, self.modules.runlogs)
self.test_dir = os.path.dirname(__file__)
@@ -62,6 +62,8 @@ def setup(self):
def teardown(self):
shutil.rmtree(self.test_db_dir)
+ shutil.rmtree(self.vmlogdir)
+ shutil.rmtree(self.runlogdir)
def test_fetch_one_vm(self):
from epumgmt.main.em_core_logfetch import _fetch_one_vm

0 comments on commit fc7a4e7

Please sign in to comment.