예제 #1
0
 def test_add_envs_dont_call_set_when_variables_dont_change(self):
     plugin = ApprcWatcher("", "", 1)
     envs = copy.deepcopy(NOPATH_OUTPUT)
     envs["options"]["env"].update(os.environ)
     plugin.call, kw = create_fake_call(None, envs)
     plugin.add_envs(name="name", envs=NOPATH_OUTPUT["options"]["env"])
     self.assertEqual([], kw)
예제 #2
0
 def test_add_envs_dont_call_set_when_variables_dont_change(self):
     plugin = ApprcWatcher("", "", 1)
     envs = copy.deepcopy(NOPATH_OUTPUT)
     envs["options"]["env"].update(os.environ)
     plugin.call, kw = create_fake_call(None, envs)
     plugin.add_envs(name="name", envs=NOPATH_OUTPUT["options"]["env"])
     self.assertEqual([], kw)
예제 #3
0
 def test_add_envs(self):
     plugin = ApprcWatcher("", "", 1)
     plugin.call, kw = create_fake_call(None)
     plugin.add_envs(name="name", envs={"foo": "bar"})
     env = copy.deepcopy(os.environ)
     env["foo"] = "bar"
     expected = [{"name": "name", "options": {"env": env}}]
     self.assertEqual(expected, kw)
예제 #4
0
 def test_add_envs(self):
     plugin = ApprcWatcher("", "", 1)
     plugin.call, kw = create_fake_call(None)
     plugin.add_envs(name="name", envs={"foo": "bar"})
     env = copy.deepcopy(os.environ)
     env["foo"] = "bar"
     expected = [{"name": "name", "options": {"env": env}}]
     self.assertEqual(expected, kw)
예제 #5
0
 def test_add_env_doesnt_ignore_PYTHONPATH_from_apprc(self):
     plugin = ApprcWatcher("", "", 1)
     plugin.call, kw = create_fake_call(None)
     plugin.add_envs(name="name", envs={"foo": "bar",
                                        "PYTHONPATH": "/usr/lib/python"})
     env = copy.deepcopy(os.environ)
     env["foo"] = "bar"
     env["PYTHONPATH"] = "/usr/lib/python"
     expected = [{"name": "name", "options": {"env": env}}]
     self.assertEqual(expected, kw)
예제 #6
0
 def test_add_env_ignores_PYTHONPATH_from_os_environ(self):
     os.environ["PYTHONPATH"] = "/home/user/python"
     self.addCleanup(remove_env, "PYTHONPATH")
     plugin = ApprcWatcher("", "", 1)
     plugin.call, kw = create_fake_call(None)
     plugin.add_envs(name="name", envs={"foo": "bar"})
     env = copy.deepcopy(os.environ)
     env["foo"] = "bar"
     del env["PYTHONPATH"]
     expected = [{"name": "name", "options": {"env": env}}]
     self.assertEqual(expected, kw)
예제 #7
0
 def test_add_env_ignores_PYTHONPATH_from_os_environ(self):
     os.environ["PYTHONPATH"] = "/home/user/python"
     self.addCleanup(remove_env, "PYTHONPATH")
     plugin = ApprcWatcher("", "", 1)
     plugin.call, kw = create_fake_call(None)
     plugin.add_envs(name="name", envs={"foo": "bar"})
     env = copy.deepcopy(os.environ)
     env["foo"] = "bar"
     del env["PYTHONPATH"]
     expected = [{"name": "name", "options": {"env": env}}]
     self.assertEqual(expected, kw)
예제 #8
0
 def test_add_envs_may_override_os_environ(self):
     os.environ["SOMETHING_UNKNOWN"] = "123"
     self.addCleanup(remove_env, "SOMETHING_UNKNOWN")
     plugin = ApprcWatcher("", "", 1)
     plugin.call, kw = create_fake_call(None)
     plugin.add_envs(name="name", envs={"foo": "bar",
                                        "SOMETHING_UNKNOWN": "456"})
     env = copy.deepcopy(os.environ)
     env["SOMETHING_UNKNOWN"] = "456"
     env["foo"] = "bar"
     expected = [{"name": "name", "options": {"env": env}}]
     self.assertEqual(expected, kw)
예제 #9
0
 def test_add_env_doesnt_ignore_PYTHONPATH_from_apprc(self):
     plugin = ApprcWatcher("", "", 1)
     plugin.call, kw = create_fake_call(None)
     plugin.add_envs(name="name",
                     envs={
                         "foo": "bar",
                         "PYTHONPATH": "/usr/lib/python"
                     })
     env = copy.deepcopy(os.environ)
     env["foo"] = "bar"
     env["PYTHONPATH"] = "/usr/lib/python"
     expected = [{"name": "name", "options": {"env": env}}]
     self.assertEqual(expected, kw)
예제 #10
0
 def test_add_envs_may_override_os_environ(self):
     os.environ["SOMETHING_UNKNOWN"] = "123"
     self.addCleanup(remove_env, "SOMETHING_UNKNOWN")
     plugin = ApprcWatcher("", "", 1)
     plugin.call, kw = create_fake_call(None)
     plugin.add_envs(name="name",
                     envs={
                         "foo": "bar",
                         "SOMETHING_UNKNOWN": "456"
                     })
     env = copy.deepcopy(os.environ)
     env["SOMETHING_UNKNOWN"] = "456"
     env["foo"] = "bar"
     expected = [{"name": "name", "options": {"env": env}}]
     self.assertEqual(expected, kw)
예제 #11
0
 def test_reload_env_skips_plugins(self):
     sr = {"statuses": {"name": "name",
                        "plugin:tsuru-circus-ApprcWatcher": "ok"}}
     fake_call, kw = create_fake_call(sr)
     plugin = ApprcWatcher("", "", 1)
     plugin.call = fake_call
     plugin.apprc = os.path.join(os.path.dirname(__file__),
                                 "testdata/apprc")
     plugin.reload_env()
     env = {"VAR1": "value-1", "port": "8888", "VAR2": "value2"}
     env.update(os.environ)
     expected = [
         {"name": "name", "options": {"env": env}},
     ]
     self.assertEqual(expected, kw)
예제 #12
0
 def test_reload_env_add_envs(self):
     sr = {"statuses": {"name": "name", "cmd": "cmd"}}
     fake_call, kw = create_fake_call(sr)
     plugin = ApprcWatcher("", "", 1)
     plugin.call = fake_call
     plugin.apprc = os.path.join(os.path.dirname(__file__),
                                 "testdata/apprc")
     plugin.reload_env()
     env = {"VAR1": "value-1", "port": "8888", "VAR2": "value2"}
     env.update(os.environ)
     expected = [
         {"name": "cmd", "options": {"env": env}},
         {"name": "name", "options": {"env": env}},
     ]
     self.assertEqual(expected, sorted(kw, key=lambda x: x["name"]))
예제 #13
0
 def test_reload_env_skips_plugins(self):
     sr = {
         "statuses": {
             "name": "name",
             "plugin:tsuru-circus-ApprcWatcher": "ok"
         }
     }
     fake_call, kw = create_fake_call(sr)
     plugin = ApprcWatcher("", "", 1)
     plugin.call = fake_call
     plugin.apprc = os.path.join(os.path.dirname(__file__),
                                 "testdata/apprc")
     plugin.reload_env()
     env = {
         "VAR1": "value-1",
         "port": "8888",
         "VAR2": "value2",
         "PORT": "8888"
     }
     env.update(os.environ)
     expected = [
         {
             "name": "name",
             "options": {
                 "env": env
             }
         },
     ]
     self.assertEqual(expected, kw)
예제 #14
0
 def test_reload_env_add_envs(self):
     sr = {"statuses": {"name": "name", "cmd": "cmd"}}
     fake_call, kw = create_fake_call(sr)
     plugin = ApprcWatcher("", "", 1)
     plugin.call = fake_call
     plugin.apprc = os.path.join(os.path.dirname(__file__),
                                 "testdata/apprc")
     plugin.reload_env()
     env = {
         "VAR1": "value-1",
         "port": "8888",
         "VAR2": "value2",
         "PORT": "8888"
     }
     env.update(os.environ)
     expected = [
         {
             "name": "cmd",
             "options": {
                 "env": env
             }
         },
         {
             "name": "name",
             "options": {
                 "env": env
             }
         },
     ]
     self.assertEqual(expected, sorted(kw, key=lambda x: x["name"]))