Ejemplo n.º 1
0
 def test_get_cmd(self):
     plugin = ProcfileWatcher("", "", 1)
     plugin.call = Mock()
     plugin.call.return_value = {"options": {"cmd": "ble"}}
     cmd = plugin.get_cmd("name")
     self.assertEqual("ble", cmd)
     plugin.call.assert_called_with("get", name="name", keys=["cmd"])
Ejemplo n.º 2
0
 def test_commands(self):
     plugin = ProcfileWatcher("", "", 1)
     result = Mock()
     result.return_value = {"statuses": {}}
     plugin.call = result
     procfile = Procfile('web: gunicorn -b 0.0.0.0:8080 abyss.wsgi\n')
     to_add, to_remove, to_change = plugin.commands(procfile)
     plugin.call.assert_called_with("status")
Ejemplo n.º 3
0
 def test_commands(self):
     plugin = ProcfileWatcher("", "", 1)
     result = Mock()
     result.return_value = {"statuses": {}}
     plugin.call = result
     procfile = Procfile('web: gunicorn -b 0.0.0.0:8080 abyss.wsgi\n')
     to_add, to_remove, to_change = plugin.commands(procfile)
     plugin.call.assert_called_with("status")
Ejemplo n.º 4
0
 def test_commands_dont_remove_tsuru_hooks_watcher(self):
     plugin = ProcfileWatcher("", "", 1)
     result = Mock()
     result.return_value = {"statuses": {"tsuru-hooks": ""}}
     plugin.call = result
     procfile = Procfile('web: gunicorn -b 0.0.0.0:8080 abyss.wsgi\n')
     to_add, to_remove, to_change = plugin.commands(procfile)
     self.assertNotIn("tsuru-hooks", to_remove)
Ejemplo n.º 5
0
 def test_reload_procfile_remove_old_cmds(self):
     plugin = ProcfileWatcher("", "", 1)
     plugin.call = Mock()
     plugin.call.return_value = {"statuses": {"name": "name", "cmd": "cmd"}}
     plugin.procfile_path = os.path.join(os.path.dirname(__file__),
                                         "testdata/Procfile2")
     plugin.reload_procfile()
     plugin.call.assert_called_with("rm", name="name")
Ejemplo n.º 6
0
 def test_commands_dont_remove_tsuru_hooks_watcher(self):
     plugin = ProcfileWatcher("", "", 1)
     result = Mock()
     result.return_value = {"statuses": {"tsuru-hooks": ""}}
     plugin.call = result
     procfile = Procfile('web: gunicorn -b 0.0.0.0:8080 abyss.wsgi\n')
     to_add, to_remove, to_change = plugin.commands(procfile)
     self.assertNotIn("tsuru-hooks", to_remove)
Ejemplo n.º 7
0
 def test_add_watcher(self):
     plugin = ProcfileWatcher("", "", 1)
     plugin.envs = lambda: {}
     plugin.circus_client = Mock()
     name = "name"
     cmd = "cmd"
     options = self.build_options(name, cmd)
     plugin.add_watcher(name=name, cmd=cmd)
     plugin.circus_client.call.assert_called_with(options)
Ejemplo n.º 8
0
 def test_should_replace_cmds_with_environ_with_braces(self):
     plugin = ProcfileWatcher("", "", 1)
     plugin.envs = lambda: {}
     plugin.circus_client = Mock()
     name = "name"
     cmd = "echo ${PORT}"
     options = self.build_options(name, "echo 8888")
     plugin.add_watcher(name=name, cmd=cmd)
     plugin.circus_client.call.assert_called_with(options)
Ejemplo n.º 9
0
 def test_get_cmd(self):
     plugin = ProcfileWatcher("", "", 1)
     plugin.call = Mock()
     plugin.call.return_value = {"options": {"cmd": "ble"}}
     cmd = plugin.get_cmd("name")
     self.assertEqual("ble", cmd)
     plugin.call.assert_called_with("get",
                                    name="name",
                                    keys=["cmd"])
Ejemplo n.º 10
0
 def test_commands_ignore_plugin(self):
     result = Mock()
     result.return_value = {"statuses":
                            {"plugin:tsuru-circus-ProcfileWatcher": "ok"}}
     plugin = ProcfileWatcher("", "", 1)
     plugin.call = result
     procfile = Procfile('web: gunicorn -b 0.0.0.0:8080 abyss.wsgi\n')
     to_add, to_remove, to_change = plugin.commands(procfile)
     self.assertEqual(set(["web"]), to_add)
     self.assertEqual(set([]), to_remove)
     self.assertEqual({}, to_change)
Ejemplo n.º 11
0
 def test_commands_ignore_plugin(self):
     result = Mock()
     result.return_value = {
         "statuses": {
             "plugin:tsuru-circus-ProcfileWatcher": "ok"
         }
     }
     plugin = ProcfileWatcher("", "", 1)
     plugin.call = result
     procfile = Procfile('web: gunicorn -b 0.0.0.0:8080 abyss.wsgi\n')
     to_add, to_remove, to_change = plugin.commands(procfile)
     self.assertEqual(set(["web"]), to_add)
     self.assertEqual(set([]), to_remove)
     self.assertEqual({}, to_change)
Ejemplo n.º 12
0
 def test_reload_procfile_add_new_cmds(self):
     plugin = ProcfileWatcher("", "", 1)
     plugin.procfile_path = os.path.join(os.path.dirname(__file__),
                                         "testdata/Procfile1")
     plugin.circus_client = Mock()
     plugin.envs = lambda: {}
     plugin.call = Mock()
     plugin.call.return_value = {"statuses": {}}
     plugin.reload_procfile()
     options = self.build_options("name", "cmd")
     plugin.circus_client.call.assert_called_with(options)
Ejemplo n.º 13
0
 def test_reload_procfile_add_new_cmds(self):
     plugin = ProcfileWatcher("", "", 1)
     plugin.procfile_path = os.path.join(os.path.dirname(__file__),
                                         "testdata/Procfile1")
     plugin.circus_client = Mock()
     plugin.envs = lambda: {}
     plugin.call = Mock()
     plugin.call.return_value = {"statuses": {}}
     plugin.reload_procfile()
     options = self.build_options("name", "cmd")
     plugin.circus_client.call.assert_called_with(options)
Ejemplo n.º 14
0
 def test_reload_procfile_remove_old_cmds(self):
     plugin = ProcfileWatcher("", "", 1)
     plugin.call = Mock()
     plugin.call.return_value = {"statuses": {"name": "name", "cmd": "cmd"}}
     plugin.procfile_path = os.path.join(os.path.dirname(__file__),
                                         "testdata/Procfile2")
     plugin.reload_procfile()
     plugin.call.assert_called_with("rm", name="name")
Ejemplo n.º 15
0
 def test_change_cmd_should_replace_cmds_with_environ(self, load_envs):
     load_envs.return_value = {"BLE": "bla"}
     plugin = ProcfileWatcher("", "", 1)
     plugin.envs = lambda: {}
     plugin.call = Mock()
     plugin.port = 8888
     name = "name"
     cmd = "echo ${PORT} ${port} ${BLE}"
     plugin.change_cmd(name=name, cmd=cmd)
     plugin.call.assert_called_with('set',
                                    options={'cmd': 'echo 8888 8888 bla'},
                                    name=name)
Ejemplo n.º 16
0
 def test_add_watcher(self):
     plugin = ProcfileWatcher("", "", 1)
     plugin.circus_client = Mock()
     name = "name"
     cmd = "cmd"
     options = json.dumps({
         "command": "add",
         "properties": {
         "cmd":  cmd,
         "name": name,
         "args": [],
         "options": {
             "env": {"port": "8888"},
             "copy_env": True,
             "working_dir": "/home/application/current",
             "stderr_stream": {"class": "tsuru.stream.Stream"},
             "stdout_stream": {"class": "tsuru.stream.Stream"},
             "uid": "ubuntu",
         },
         "start": True,
     }})
     plugin.add_watcher(name=name, cmd=cmd)
     plugin.circus_client.call.assert_called_with(options)
Ejemplo n.º 17
0
 def test_should_replace_cmds_with_environ_with_braces(self):
     plugin = ProcfileWatcher("", "", 1)
     plugin.envs = lambda: {}
     plugin.circus_client = Mock()
     name = "name"
     cmd = "echo ${PORT}"
     options = self.build_options(name, "echo 8888")
     plugin.add_watcher(name=name, cmd=cmd)
     plugin.circus_client.call.assert_called_with(options)
Ejemplo n.º 18
0
 def test_add_watcher(self):
     plugin = ProcfileWatcher("", "", 1)
     plugin.envs = lambda: {}
     plugin.circus_client = Mock()
     name = "name"
     cmd = "cmd"
     options = self.build_options(name, cmd)
     plugin.add_watcher(name=name, cmd=cmd)
     plugin.circus_client.call.assert_called_with(options)
Ejemplo n.º 19
0
 def test_reload_procfile_update_cmds(self):
     plugin = ProcfileWatcher("", "", 1)
     plugin.call = Mock()
     plugin.call.return_value = {"statuses": {"name": "name", "cmd": "cmd"}}
     plugin.get_cmd = Mock()
     plugin.get_cmd.return_value = "cmd"
     plugin.procfile_path = os.path.join(os.path.dirname(__file__),
                                         "testdata/Procfile3")
     plugin.reload_procfile()
     plugin.get_cmd.assert_called_with("name")
     plugin.call.assert_called_with("set",
                                    name="name",
                                    options={'cmd': 'cmd2'})
Ejemplo n.º 20
0
 def test_change_cmd_should_replace_cmds_with_environ(self, load_envs):
     load_envs.return_value = {"BLE": "bla"}
     plugin = ProcfileWatcher("", "", 1)
     plugin.envs = lambda: {}
     plugin.call = Mock()
     plugin.port = 8888
     name = "name"
     cmd = "echo ${PORT} ${BLE}"
     plugin.change_cmd(name=name, cmd=cmd)
     plugin.call.assert_called_with('set',
                                    options={'cmd': 'echo 8888 bla'},
                                    name=name)
Ejemplo n.º 21
0
 def test_reload_procfile_update_cmds(self):
     plugin = ProcfileWatcher("", "", 1)
     plugin.call = Mock()
     plugin.call.return_value = {"statuses": {"name": "name", "cmd": "cmd"}}
     plugin.get_cmd = Mock()
     plugin.get_cmd.return_value = "cmd"
     plugin.procfile_path = os.path.join(os.path.dirname(__file__),
                                         "testdata/Procfile3")
     plugin.reload_procfile()
     plugin.get_cmd.assert_called_with("name")
     plugin.call.assert_called_with("set",
                                    name="name",
                                    options={'cmd': 'cmd2'})
Ejemplo n.º 22
0
 def test_plugin(self):
     plugin = ProcfileWatcher("", "", 1)
     self.assertIsInstance(plugin, ProcfileWatcher)
Ejemplo n.º 23
0
 def test_remove_watcher(self):
     plugin = ProcfileWatcher("", "", 1)
     plugin.call = Mock()
     name = "name"
     plugin.remove_watcher(name=name)
     plugin.call.assert_called_with("rm", name=name)
Ejemplo n.º 24
0
 def test_remove_watcher(self):
     plugin = ProcfileWatcher("", "", 1)
     plugin.call = Mock()
     name = "name"
     plugin.remove_watcher(name=name)
     plugin.call.assert_called_with("rm", name=name)