def test_bad_script(self):
     try:
         run_and_return_output(self.create_context({}),
                               script_path="bad.sh")
         self.fail("Expected exception")
     except ProcessException as e:
         self.assertEqual(5, e.exit_code)
    def test_scripts(self):

        scripts = {
            'start': 'ls.sh'
        }

        run_and_return_output(self.create_context({'scripts': scripts}))
 def test_bad_script(self):
     try:
         run_and_return_output(self.create_context({}),
                               script_path="bad.sh")
         self.fail("Expected exception")
     except ProcessException as e:
         self.assertEqual(5, e.exit_code)
    def test_download_resource(self):

        expected_path = "/tmp/index.html"  # see test_file_server.sh
        if os.path.exists(expected_path):  # cleanup
            os.remove(expected_path)

        run_and_return_output(self.create_context({}),
                              script_path="test_file_server.sh",
                              log_all=False)

        # check the download_resource actually worked
        self.assertTrue(os.path.exists(expected_path))
    def test_download_resource(self):

        expected_path = "/tmp/index.html"  # see test_file_server.sh
        if os.path.exists(expected_path):  # cleanup
            os.remove(expected_path)

        run_and_return_output(self.create_context({}),
                              script_path="test_file_server.sh",
                              log_all=False)

        # check the download_resource actually worked
        self.assertTrue(os.path.exists(expected_path))
    def test_environment_injection(self):

        properties = {
            'port': 8080,  # test integer
            'url': 'http://localhost',  # test string
            'node_id': u'node_id'  # test unicode
        }

        out = run_and_return_output(self.create_context(properties),
                                    script_path="env.sh")

        expected_dict = {
            'CLOUDIFY_NODE_ID': 'test',
            'CLOUDIFY_BLUEPRINT_ID': '',
            'CLOUDIFY_DEPLOYMENT_ID': 'test',
            'CLOUDIFY_MANAGER_IP': 'localhost',
            'CLOUDIFY_EXECUTION_ID': 'test',
            'CLOUDIFY_FILE_SERVER_BLUEPRINT_ROOT': 'http://localhost:53229/',
            'port': 8080,
            'url': 'http://localhost',
            'node_id': 'node_id'
        }

        actual_dict = properties_to_dict(out)
        for key in expected_dict:
            self.assertEqual(expected_dict[key], actual_dict[key])
    def test_environment_injection(self):

        properties = {
            'port': 8080,  # test integer
            'url': 'http://localhost',  # test string
            'node_id': u'node_id'  # test unicode
        }

        out = run_and_return_output(self.create_context(properties),
                                    script_path="env.sh")

        expected_dict = {
            'CLOUDIFY_NODE_ID': 'test',
            'CLOUDIFY_BLUEPRINT_ID': '',
            'CLOUDIFY_DEPLOYMENT_ID': 'test',
            'CLOUDIFY_MANAGER_IP': 'localhost',
            'CLOUDIFY_EXECUTION_ID': 'test',
            'CLOUDIFY_FILE_SERVER_BLUEPRINT_ROOT': 'http://localhost:53229/',
            'port': 8080,
            'url': 'http://localhost',
            'node_id': 'node_id'
        }

        actual_dict = properties_to_dict(out)
        for key in expected_dict:
            self.assertEqual(expected_dict[key], actual_dict[key])
    def test_no_script_mapping_for_operation(self):

        scripts = {
            'stop': 'ls.sh'
        }

        out = run_and_return_output(self.create_context({'scripts': scripts}))
        self.assertIsNone(out)
    def test_logging(self):

        out = run_and_return_output(self.create_context({}),
                                    script_path="test_logging.sh")
        line = out.splitlines()
        self.assertEqual(line[0],
                         "[INFO] [test_logging.sh] THIS IS AN INFO PRINT")
        self.assertEqual(line[1],
                         "[ERROR] [test_logging.sh] THIS IS AN ERROR PRINT")
    def test_logging(self):

        out = run_and_return_output(self.create_context({}),
                                    script_path="test_logging.sh")
        line = out.splitlines()
        self.assertEqual(line[0],
                         "[INFO] [test_logging.sh] THIS IS AN INFO PRINT")
        self.assertEqual(line[1],
                         "[ERROR] [test_logging.sh] THIS IS AN ERROR PRINT")
    def test_complex_property(self):

        properties = {'port': {'a': 1}}

        out = run_and_return_output(self.create_context(properties),
                                    script_path="env-with-complex-prop.sh")

        expected_dict = {'port_a': 1}

        actual_dict = properties_to_dict(out)
        for key in expected_dict:
            self.assertEqual(expected_dict[key], actual_dict[key])
    def test_complex_property(self):

        properties = {
            'port': {
                'a': 1
            }
        }

        out = run_and_return_output(self.create_context(properties),
                                    script_path="env-with-complex-prop.sh")

        expected_dict = {
            'port_a': 1
        }

        actual_dict = properties_to_dict(out)
        for key in expected_dict:
            self.assertEqual(expected_dict[key], actual_dict[key])
 def test_script_path(self):
     run_and_return_output(self.create_context({}), script_path="ls.sh")
    def test_scripts(self):

        scripts = {'start': 'ls.sh'}

        run_and_return_output(self.create_context({'scripts': scripts}))
 def test_script_path(self):
     run_and_return_output(self.create_context({}), script_path="ls.sh")
    def test_no_script_mapping_for_operation(self):

        scripts = {'stop': 'ls.sh'}

        out = run_and_return_output(self.create_context({'scripts': scripts}))
        self.assertIsNone(out)