def test_binary_path_not_executable(isfile_mock, access_mock):
    """
    tests if binary is not executable
    """
    isfile_mock.return_value = True
    access_mock.return_value = False
    output = binary_path('test_localhost_helpers.py')
    assert output is None
def test_binary_path_fpath_exists(isfile_mock, access_mock):
    """
    Tests if binary is in path and fpath is true
    """
    isfile_mock.return_value = True
    access_mock.return_value = True
    output = binary_path('python')
    assert '/bin/python' in output
def test_binary_path_doesnot_exist(isfile_mock, access_mock):
    """
    Tests if binary is not in path
    """
    isfile_mock.return_value = False
    access_mock.return_value = False
    output = binary_path('pyth0n')
    assert output is None
def test_binary_path_exists(isfile_mock, access_mock, ospath_split_mock):
    """
    Tests if binary is in path
    """
    isfile_mock.return_value = True
    access_mock.return_value = True
    ospath_split_mock.return_value = ('path', 'name')
    output = binary_path('python')
    assert output == 'python'
Beispiel #5
0
    def action(self):
        """Creates a new git repository based on an mlt template in the
           current working directory.
        """
        template_name = self.args["--template"]
        template_repo = self.args["--template-repo"]
        skip_crd_check = self.args["--skip-crd-check"]
        with git_helpers.clone_repo(template_repo) as temp_clone:
            templates_directory = os.path.join(temp_clone,
                                               constants.TEMPLATES_DIR,
                                               template_name)

            try:
                # The template configs get pulled into the mlt.json file, so
                # don't grab a copy of that in this app's directory
                copytree(templates_directory,
                         self.app_name,
                         ignore=ignore_patterns(constants.TEMPLATE_CONFIG))

                # Get the template configs from the template and include them
                # when building the mlt json file
                param_file = os.path.join(templates_directory,
                                          constants.TEMPLATE_CONFIG)
                template_params = config_helpers.\
                    get_template_parameters_from_file(param_file)
                template_git_sha = git_helpers.get_latest_sha(
                    os.path.join(temp_clone, constants.TEMPLATES_DIR,
                                 template_name))
                if not skip_crd_check:
                    kubernetes_helpers.check_crds(app_name=self.app_name)

                if self.args["--enable-sync"]:
                    if localhost_helpers.binary_path('ksync'):
                        # Syncthing uses '.stignore' to ignore files during
                        # sync we also don't want to upload unneeded local data
                        app_ignore_file = os.path.join(self.app_name,
                                                       ".gitignore")
                        ksync_ignore_file = os.path.join(
                            self.app_name, ".stignore")
                        if self._check_update_yaml_for_sync():
                            copyfile(app_ignore_file, ksync_ignore_file)
                            with open(ksync_ignore_file, 'a+') as f:
                                f.write("\n.git/**")
                        else:
                            error_handling.throw_error(
                                "This app doesn't support syncing", 'yellow')
                    else:
                        error_handling.throw_error(
                            "ksync is not installed on localhost.", 'red')

                data = self._build_mlt_json(template_params, template_git_sha)

                # If the app has option for debugging failures, grab the
                # Kubernetes debug wrapper file and put it in the app directory
                if any(param["name"] == "debug_on_fail"
                       for param in template_params):
                    self._enable_debug_on_fail(temp_clone)

                with open(os.path.join(self.app_name, constants.MLT_CONFIG),
                          'w') as f:
                    json.dump(data, f, indent=2)

                self._init_git_repo()
            except OSError as exc:
                if exc.errno == 17:
                    error_msg = "Directory '{}' already exists: ".format(
                        self.app_name) + \
                        "delete before trying to initialize new application"
                    color = 'red'
                else:
                    error_msg = traceback.format_exc()
                    color = None
                error_handling.throw_error(error_msg, color)