def generate_state_file():
    state_file_name = "state.conf"
    if configuration.get_state_directory_path() == configuration.DEFAULT_STATE_DIRECTORY_PATH:
        state_file_path = os.path.join(configuration.get_working_directory_path(), state_file_name)
    else:
        state_file_path = os.path.join(configuration.get_state_directory_path(), state_file_name)

    tracer.log_debug_trace("State file path : " + str(state_file_path))

    if os.path.isfile(state_file_path):
        os.remove(state_file_path)

    section = "state"
    conf_file = open(state_file_path, 'wb')
    config = ConfigParser.ConfigParser()
    config.add_section(section)
    config.set(section, configuration.STATE_PID, str(os.getpid()))
    config.set(section, configuration.WORKER_VERSION, str(configuration.get_worker_version()))

    # for OMS scenarios, optional for DIY
    if len(sys.argv) >= 3:
        config.set(section, configuration.STATE_WORKSPACE_ID, str(sys.argv[2]))

    if len(sys.argv) >= 4:
        config.set(section, configuration.STATE_RESOURCE_VERSION, str(sys.argv[3]))

    config.write(conf_file)
    conf_file.close()
def validate_and_setup_path():
    # default to user dir for exception logs to be writen to disk
    test_file_name = "test_file"

    # test certificate and key path
    if not os.path.isfile(configuration.get_jrds_cert_path()) or not os.path.isfile(configuration.get_jrds_key_path()):
        exit_on_error("Invalid certificate of key file path (absolute path is required).")

    # test working dirextory for existance and permissions
    if not os.path.exists(configuration.get_working_directory_path()):
        exit_on_error("Invalid working directory path (absolute path is required).")
    file_creation = test_file_creation(os.path.join(configuration.get_working_directory_path(), test_file_name))
    if file_creation is False:
        exit_on_error("Invalid working directory permission (read/write permissions are required).")

    # test keyring paths
    keyring_path = configuration.get_gpg_public_keyring_path()
    if keyring_path != configuration.DEFAULT_GPG_PUBLIC_KEYRING_PATH and not os.path.isfile(keyring_path):
        exit_on_error("Invalid gpg public keyring path (absolute path is required).")

    # test state file path
    if configuration.get_state_directory_path() != configuration.DEFAULT_STATE_DIRECTORY_PATH:
        if not os.path.exists(configuration.get_state_directory_path()):
            exit_on_error("Invalid state directory path (absolute path is required).")

        file_creation = test_file_creation(os.path.join(configuration.get_state_directory_path(), test_file_name))
        if file_creation is False:
            exit_on_error("Invalid state directory permission (read/write permissions are required).")
Beispiel #3
0
def generate_state_file():
    state_file_name = "state.conf"
    if configuration.get_state_directory_path(
    ) == configuration.DEFAULT_STATE_DIRECTORY_PATH:
        state_file_path = os.path.join(
            configuration.get_working_directory_path(), state_file_name)
    else:
        state_file_path = os.path.join(
            configuration.get_state_directory_path(), state_file_name)

    tracer.log_debug_trace("State file path : " + str(state_file_path))

    if os.path.isfile(state_file_path):
        os.remove(state_file_path)

    section = "state"
    conf_file = open(state_file_path, 'wb')
    config = ConfigParser.ConfigParser()
    config.add_section(section)
    config.set(section, configuration.STATE_PID, str(os.getpid()))
    config.set(section, configuration.WORKER_VERSION,
               str(configuration.get_worker_version()))

    # for OMS scenarios, optional for DIY
    if len(sys.argv) >= 3:
        config.set(section, configuration.STATE_WORKSPACE_ID, str(sys.argv[2]))

    if len(sys.argv) >= 4:
        config.set(section, configuration.STATE_RESOURCE_VERSION,
                   str(sys.argv[3]))

    config.write(conf_file)
    conf_file.close()
Beispiel #4
0
def validate_and_setup_path():
    # default to user dir for exception logs to be writen to disk
    test_file_name = "test_file"

    # test certificate and key path
    if not os.path.isfile(
            configuration.get_jrds_cert_path()) or not os.path.isfile(
                configuration.get_jrds_key_path()):
        exit_on_error(
            "Invalid certificate of key file path (absolute path is required)."
        )

    # test working dirextory for existance and permissions
    if not os.path.exists(configuration.get_working_directory_path()):
        exit_on_error(
            "Invalid working directory path (absolute path is required).")
    file_creation = test_file_creation(
        os.path.join(configuration.get_working_directory_path(),
                     test_file_name))
    if file_creation is False:
        exit_on_error(
            "Invalid working directory permission (read/write permissions are required)."
        )

    # test keyring paths
    keyring_path = configuration.get_gpg_public_keyring_path()
    if keyring_path != configuration.DEFAULT_GPG_PUBLIC_KEYRING_PATH and not os.path.isfile(
            keyring_path):
        exit_on_error(
            "Invalid gpg public keyring path (absolute path is required).")

    # test state file path
    if configuration.get_state_directory_path(
    ) != configuration.DEFAULT_STATE_DIRECTORY_PATH:
        if not os.path.exists(configuration.get_state_directory_path()):
            exit_on_error(
                "Invalid state directory path (absolute path is required).")

        file_creation = test_file_creation(
            os.path.join(configuration.get_state_directory_path(),
                         test_file_name))
        if file_creation is False:
            exit_on_error(
                "Invalid state directory permission (read/write permissions are required)."
            )
Beispiel #5
0
def validate_and_setup_path():
    # default to user dir for exception logs to be writen to disk
    test_file_name = "test_file"

    # test certificate and key path
    if not os.path.isfile(
            configuration.get_jrds_cert_path()) or not os.path.isfile(
                configuration.get_jrds_key_path()):
        exit_on_error(
            "Invalid certificate of key file path (absolute path is required)."
        )

    # test working directory for existence and permissions
    working_directory_path = configuration.get_working_directory_path()
    if not os.path.exists(working_directory_path):
        exit_on_error(
            "Invalid working directory path (absolute path is required).")

    file_creation = test_file_creation(
        os.path.join(working_directory_path, test_file_name))
    if file_creation is False:
        exit_on_error(
            "Invalid working directory permission (read/write permissions are required)."
        )

    # test keyring paths
    keyrings = configuration.get_gpg_public_keyrings_path()
    for keyring_path in keyrings:
        if keyring_path != configuration.DEFAULT_GPG_PUBLIC_KEYRING_PATH and not os.path.isfile(
                keyring_path):
            exit_on_error(
                "Invalid gpg public keyring path (absolute path is required).")

    # test state file path
    if configuration.get_state_directory_path(
    ) != configuration.DEFAULT_STATE_DIRECTORY_PATH:
        if not os.path.exists(configuration.get_state_directory_path()):
            exit_on_error(
                "Invalid state directory path (absolute path is required).")

        file_creation = test_file_creation(
            os.path.join(configuration.get_state_directory_path(),
                         test_file_name))
        if file_creation is False:
            exit_on_error(
                "Invalid state directory permission (read/write permissions are required)."
            )

    # OMS integration
    # set the working directory owner to be nxautomation:omiusers
    if os.name.lower() != "nt":
        import pwd
        try:
            nxautomation_uid = int(pwd.getpwnam('nxautomation').pw_uid)
            if os.getuid() == nxautomation_uid:
                retval = subprocess.call([
                    "sudo", "chown", "-R", "nxautomation:omiusers",
                    working_directory_path
                ])
                if retval != 0:
                    exit_on_error(
                        "Could not change owner of working directory %s to nxautomation:omiusers"
                        % (working_directory_path))
        except KeyError:
            # nxautomation user was not found on the system, skip this step
            tracer.log_debug_trace(
                "Ownership change of working directory skipped. nxautomation user not found."
            )
            pass
Beispiel #6
0
def generate_state_file():
    state_file_name = "state.conf"
    if configuration.get_state_directory_path(
    ) == configuration.DEFAULT_STATE_DIRECTORY_PATH:
        state_file_path = os.path.join(
            configuration.get_working_directory_path(), state_file_name)
    else:
        state_file_path = os.path.join(
            configuration.get_state_directory_path(), state_file_name)

    tracer.log_debug_trace("State file path : " + str(state_file_path))

    if os.path.isfile(state_file_path):
        os.remove(state_file_path)

    section = "state"
    conf_file = open(state_file_path, 'wb')
    config = ConfigParser.ConfigParser()
    config.add_section(section)
    config.set(section, configuration.STATE_PID, str(os.getpid()))
    config.set(section, configuration.WORKER_VERSION,
               str(configuration.get_worker_version()))

    # for OMS scenarios, optional for DIY
    if len(sys.argv) >= 3:
        config.set(section, configuration.STATE_WORKSPACE_ID, str(sys.argv[2]))

    if len(sys.argv) >= 4:
        config.set(section, configuration.STATE_RESOURCE_VERSION,
                   str(sys.argv[3]))

    config.write(conf_file)
    conf_file.close()

    # OMS integration
    # set the ownership of the state file to nxautomation:omiusers
    # set the permission of the state file to 660
    if os.name.lower() != "nt":
        import pwd
        try:
            nxautomation_uid = int(pwd.getpwnam('nxautomation').pw_uid)
            if os.getuid() == nxautomation_uid:
                retval = subprocess.call([
                    "sudo", "chown", "nxautomation:omiusers", state_file_path
                ])
                if retval != 0:
                    exit_on_error(
                        "Could not change owner of state file %s to nxautomation:omiusers"
                        % (state_file_path))

                retval = subprocess.call(
                    ["sudo", "chmod", "660", state_file_path])
                if retval != 0:
                    exit_on_error(
                        "Could not change permission of state file %s " %
                        (state_file_path))
        except KeyError:
            # nxautomation user was not found on the system, skip this step
            tracer.log_debug_trace(
                "State file permission change skipped. nxautomation user not found."
            )
            pass