Ejemplo n.º 1
0
 def test_save_parse_apprc_escaping(self):
     expected = {
         "A": "B",
         "C": "C D",
         "b": "888",
         "B": "9\"1",
         "D": "X=y",
         "F": "a(a) + (",
         "MY_awesome_BIG_name": "some'thin'g'",
         "JSON": '[{"a": "b", "c": {"d": "f"}}]',
         "SLASHED": "a\\a escaped \\\" some \\\"",
         "EXEC": "a: `echo hey` b: $(echo again)",
         "MULTILINE":
         "my\nmulti\"line\", with ' quotes ' yay'\nvariable'\n'",
     }
     path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                         "fixtures", "written_apprc")
     try:
         save_apprc_file(expected, file_path=path)
         envs = parse_apprc_file(path)
         for k, v in envs.items():
             if k not in expected:
                 envs.pop(k)
         self.assertEqual(envs, expected)
     finally:
         os.remove(path)
Ejemplo n.º 2
0
 def test_save_apprc_file(self):
     environs = {"DATABASE_HOST": "localhost", "DATABASE_USER": "******"}
     with mock.patch("io.open", mock.mock_open()) as m:
         save_apprc_file(environs)
         m.assert_called_once_with("/home/application/apprc", "w")
         write_mock = m().write
         self.assertRegexpMatches(write_mock.mock_calls[0][1][0],
                                  '# generated by tsuru at .*\n')
         write_mock.assert_any_call('export DATABASE_HOST=\'localhost\'\n')
         write_mock.assert_any_call('export DATABASE_USER=\'root\'\n')
         self.assertEqual(len(write_mock.mock_calls), 3)
Ejemplo n.º 3
0
 def test_save_apprc_file(self):
     environs = {"DATABASE_HOST": "localhost", "DATABASE_USER": "******"}
     with mock.patch("io.open", mock.mock_open()) as m:
         save_apprc_file(environs)
         m.assert_called_once_with("/home/application/apprc", "w")
         write_mock = m().write
         self.assertRegexpMatches(write_mock.mock_calls[0][1][0],
                                  '# generated by tsuru at .*\n')
         write_mock.assert_any_call('export DATABASE_HOST=\'localhost\'\n')
         write_mock.assert_any_call('export DATABASE_USER=\'root\'\n')
         self.assertEqual(len(write_mock.mock_calls), 3)
Ejemplo n.º 4
0
def deploy_action(args):
    heartbeat.StderrHeartbeat().start()
    client = Client(args.url, args.token)
    envs = client.register_unit(args.app_name)
    tasks.save_apprc_file(envs)
    tasks.execute_start_script(args.start_cmd)
    yaml_data = tasks.load_app_yaml()
    yaml_data["procfile"] = tasks.load_procfile()
    client.register_unit(args.app_name, yaml_data)
    client.post_app_yaml(args.app_name, yaml_data)
    tasks.run_build_hooks(yaml_data, envs=envs)
    tasks.write_circus_conf(envs=envs)
Ejemplo n.º 5
0
def run_action(args):
    client = Client(args.url, args.token)
    envs = None
    try:
        envs = client.register_unit(args.app_name)
        tasks.save_apprc_file(envs)
    except ConnectionError:
        envs = tasks.parse_apprc_file()
    yaml_data = tasks.load_app_yaml()
    tasks.write_circus_conf(envs=envs)
    tasks.run_restart_hooks('before', yaml_data, envs=envs)
    tasks.execute_start_script(args.start_cmd, envs=envs, with_shell=False)
    tasks.run_restart_hooks('after', yaml_data, envs=envs)
Ejemplo n.º 6
0
def save_apprc_file(envs, supported_tsuru):
    no_apprc_version = semantic_version.Version("0.17.0")
    supported_version = semantic_version.Version(supported_tsuru)
    port_envs = {"port": "8888", "PORT": "8888"}
    if supported_version < no_apprc_version:
        tasks.save_apprc_file(envs)
    else:
        tasks.save_apprc_file(port_envs)
        tasks.save_apprc_file(envs, file_path=TEMP_ENV_FILE)
Ejemplo n.º 7
0
def save_apprc_file(envs, supported_tsuru):
    no_apprc_version = semantic_version.Version("0.17.0")
    supported_version = semantic_version.Version(supported_tsuru)
    port_envs = {"port": "8888", "PORT": "8888"}
    if supported_version < no_apprc_version:
        tasks.save_apprc_file(envs)
    else:
        tasks.save_apprc_file(port_envs)
        tasks.save_apprc_file(envs, file_path=TEMP_ENV_FILE)
Ejemplo n.º 8
0
 def test_save_parse_apprc_escaping(self):
     expected = {
         "A": "B",
         "C": "C D",
         "b": "888",
         "B": "9\"1",
         "D": "X=y",
         "F": "a(a) + (",
         "MY_awesome_BIG_name": "some'thin'g'",
         "JSON": '[{"a": "b", "c": {"d": "f"}}]',
         "SLASHED": "a\\a escaped \\\" some \\\"",
         "EXEC": "a: `echo hey` b: $(echo again)",
         "MULTILINE": "my\nmulti\"line\", with ' quotes ' yay'\nvariable'\n'",
     }
     path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "fixtures", "written_apprc")
     try:
         save_apprc_file(expected, file_path=path)
         envs = parse_apprc_file(path)
         for k, v in envs.items():
             if k not in expected:
                 envs.pop(k)
         self.assertEqual(envs, expected)
     finally:
         os.remove(path)