Skip to content
This repository
Browse code

More tests. Now with 50% test coverage!

  • Loading branch information...
commit fc7a4e7e15954674fa21863ae72fcc5262f50e2e 1 parent 93182d6
Patrick Armstrong authored
2  src/python/epumgmt/defaults/svc_adapter.py
@@ -252,9 +252,11 @@ def _find_controllers_from_svc(self, service_type):
252 252
         """
253 253
         svc = get_cloudinitd_service(self.cloudinitd, service_type)
254 254
         allkeys = svc.get_keys_from_bag()
  255
+        print allkeys
255 256
         controllers = []
256 257
         for key in allkeys:
257 258
             if key.startswith(self.controller_prefix):
  259
+                print "Whoop"
258 260
                 controllers.append(svc.get_attr_from_bag(key))
259 261
         return controllers
260 262
 
2  src/python/tests/mocks/modules.py
@@ -20,7 +20,7 @@ def __init__(self, remote_svc_adapter=None, runlogs=None):
20 20
         self.persistence = FakePersistence()
21 21
         self.runlogs = runlogs
22 22
 
23  
-def build_fake_scp_command_str(target, real_scp_command_str):
  23
+def make_fake_scp_command_str(target, real_scp_command_str):
24 24
     def fake_scp_command_str(target, c, vm, cloudinitd):
25 25
         scpcmd = real_scp_command_str(c, vm, cloudinitd)
26 26
         scpcmd = "echo %s" % scpcmd
4  src/python/tests/test_epumgmt_defaults_cloudinitd_load.py
@@ -13,7 +13,7 @@
13 13
 
14 14
 from mocks.common import FakeCommon
15 15
 from mocks.modules import FakeModules
16  
-from mocks.modules import build_fake_scp_command_str
  16
+from mocks.modules import make_fake_scp_command_str
17 17
 from mocks.remote_svc_adapter import FakeRemoteSvcAdapter
18 18
 
19 19
 class TestCloudinitdLoad:
@@ -48,7 +48,7 @@ def setup(self):
48 48
         runlogs = DefaultRunlogs(self.params, self.common)
49 49
         runlogs.validate()
50 50
         self.modules.runlogs = runlogs
51  
-        new_get_scp = build_fake_scp_command_str(runlogs, runlogs.get_scp_command_str)
  51
+        new_get_scp = make_fake_scp_command_str(runlogs, runlogs.get_scp_command_str)
52 52
         self.modules.runlogs.get_scp_command_str = types.MethodType(new_get_scp, self.modules.runlogs)
53 53
 
54 54
         self.test_dir = os.path.dirname(__file__)
80  src/python/tests/test_epumgmt_defaults_svc_adapter.py
... ...
@@ -1,6 +1,9 @@
1  
-import nose.tools
2 1
 import os
  2
+import re
  3
+import types
  4
+import shutil
3 5
 import tempfile
  6
+import nose.tools
4 7
 import ConfigParser
5 8
 
6 9
 import epumgmt.defaults.svc_adapter
@@ -9,7 +12,8 @@
9 12
 
10 13
 from epumgmt.api.exceptions import *
11 14
 from epumgmt.api import  RunVM
12  
-from epumgmt.defaults.parameters import DefaultParameters
  15
+from epumgmt.defaults import DefaultParameters
  16
+from epumgmt.defaults import DefaultRunlogs
13 17
 from mocks.common import FakeCommon
14 18
 from mocks.modules import FakeModules
15 19
 
@@ -42,6 +46,11 @@ def setup(self):
42 46
         self.run_name = "TESTRUN"
43 47
 
44 48
         self.config = ConfigParser.RawConfigParser()
  49
+        self.config.add_section("events")
  50
+        self.runlogdir = tempfile.mkdtemp()
  51
+        self.config.set("events", "runlogdir", self.runlogdir)
  52
+        self.vmlogdir = tempfile.mkdtemp()
  53
+        self.config.set("events", "vmlogdir", self.vmlogdir)
45 54
         self.config.add_section("svcadapter")
46 55
         self.config.set("svcadapter", "controller_prefix", "controller")
47 56
         self.config.set("svcadapter", "homedir", "app")
@@ -53,15 +62,30 @@ def setup(self):
53 62
         self.p.optdict = self.optdict
54 63
 
55 64
 
  65
+
56 66
         self.m = FakeModules()
57 67
         self.c = FakeCommon()
58 68
         self.svc_adapter = DefaultRemoteSvcAdapter(self.p, self.c)
59 69
 
  70
+        runlogs = DefaultRunlogs(self.p, self.c)
  71
+        self.m.runlogs = runlogs
  72
+        runlogs.validate()
  73
+
  74
+        new_run_one_cmd = make_fake_run_one_cmd(self.svc_adapter,
  75
+                                                self.svc_adapter._run_one_cmd)
  76
+        self.svc_adapter._run_one_cmd = types.MethodType(new_run_one_cmd,
  77
+                                                         self.svc_adapter)
  78
+
60 79
         self.test_dir = os.path.dirname(__file__)
61 80
         self.test_db_dir = tempfile.mkdtemp()
62 81
         self.test_cd_config = os.path.join(self.test_dir, "configs/main.conf")
63 82
         self.cloudinitd = CloudInitD(self.test_db_dir, self.test_cd_config, self.run_name)
64 83
 
  84
+    def teardown(self):
  85
+        
  86
+        shutil.rmtree(self.test_db_dir)
  87
+        shutil.rmtree(self.runlogdir)
  88
+        shutil.rmtree(self.vmlogdir)
65 89
 
66 90
     def test_worker_state(self):
67 91
 
@@ -103,3 +127,55 @@ def test_worker_state(self):
103 127
         assert raised_incompatible_env
104 128
 
105 129
 
  130
+        provisioner.hostname = "some.fake.hostname"
  131
+        provisioner.service_type = "provisioner"
  132
+        provisioner.runlogdir = self.runlogdir
  133
+        self.svc_adapter.provisioner._svc._s.hostname = provisioner.hostname
  134
+        try:
  135
+            self.svc_adapter.worker_state(controllers, provisioner)
  136
+        except UnexpectedError as e:
  137
+            print e.msg
  138
+            assert "Expecting to find the state query result here" in e.msg
  139
+
  140
+        ssh_commands = [message for (level, message)
  141
+                        in self.c.log.transcript 
  142
+                        if level == "DEBUG"
  143
+                           and "command = 'echo ssh" in message]
  144
+        ssh_command = ssh_commands[0]
  145
+
  146
+        # Make sure epu-state called for provisioner
  147
+        assert re.match(".*ssh.*%s.*epu-state" % provisioner.hostname, ssh_command)
  148
+        # Make sure we query both controllers
  149
+        assert re.match(".*epu-state.*%s" % controllers[0], ssh_command)
  150
+        assert re.match(".*epu-state.*%s" % controllers[1], ssh_command)
  151
+
  152
+
  153
+    def test_reconcile_relative_conf(self):
  154
+
  155
+        absolute_dir = "/path/to/conf"
  156
+        relative_dir = "path/to/conf"
  157
+        user = "thetestuser"
  158
+
  159
+        self.svc_adapter.initialize(self.m, self.run_name, self.cloudinitd)
  160
+        got_path = self.svc_adapter._reconcile_relative_conf(absolute_dir, "", "")
  161
+
  162
+        assert got_path == absolute_dir
  163
+
  164
+        try:
  165
+            got_path = self.svc_adapter._reconcile_relative_conf(relative_dir, "", "")
  166
+            raised_incompatible_env = False
  167
+        except IncompatibleEnvironment:
  168
+            raised_incompatible_env = True
  169
+
  170
+        assert raised_incompatible_env
  171
+
  172
+        got_path = self.svc_adapter._reconcile_relative_conf(relative_dir, user, "")
  173
+        assert got_path == "/home/%s/%s" % (user, relative_dir)
  174
+
  175
+
  176
+def make_fake_run_one_cmd(target, real_run_one_cmd):
  177
+    def fake_run_one_cmd(target, cmd):
  178
+        cmd = "echo %s" % cmd
  179
+        return real_run_one_cmd(cmd)
  180
+
  181
+    return fake_run_one_cmd
6  src/python/tests/test_epumgmt_main_em_core_logfetch.py
@@ -15,7 +15,7 @@
15 15
 
16 16
 from mocks.common import FakeCommon
17 17
 from mocks.modules import FakeModules
18  
-from mocks.modules import build_fake_scp_command_str
  18
+from mocks.modules import make_fake_scp_command_str
19 19
 from mocks.remote_svc_adapter import FakeRemoteSvcAdapter
20 20
 from mocks.event import Event
21 21
 
@@ -52,7 +52,7 @@ def setup(self):
52 52
         runlogs = DefaultRunlogs(self.params, self.common)
53 53
         runlogs.validate()
54 54
         self.modules.runlogs = runlogs
55  
-        new_get_scp = build_fake_scp_command_str(runlogs, runlogs.get_scp_command_str)
  55
+        new_get_scp = make_fake_scp_command_str(runlogs, runlogs.get_scp_command_str)
56 56
         self.modules.runlogs.get_scp_command_str = types.MethodType(new_get_scp, self.modules.runlogs)
57 57
 
58 58
         self.test_dir = os.path.dirname(__file__)
@@ -62,6 +62,8 @@ def setup(self):
62 62
 
63 63
     def teardown(self):
64 64
         shutil.rmtree(self.test_db_dir)
  65
+        shutil.rmtree(self.vmlogdir)
  66
+        shutil.rmtree(self.runlogdir)
65 67
 
66 68
     def test_fetch_one_vm(self):
67 69
         from epumgmt.main.em_core_logfetch import _fetch_one_vm

0 notes on commit fc7a4e7

Please sign in to comment.
Something went wrong with that request. Please try again.