brpm_content 0.1.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +38 -0
- data/.travis.yml +14 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +308 -0
- data/Rakefile +24 -0
- data/TO_BE_MIGRATED.txt +8 -0
- data/architecture.png +0 -0
- data/brpm_content.gemspec +31 -0
- data/customers/demo/integrations/brpm/process_event_handler_event.rb +183 -0
- data/customers/demo/integrations/jenkins/spec/api/applications_spec.rb +89 -0
- data/customers/demo/integrations/jenkins/spec/api/plans_spec.rb +69 -0
- data/customers/demo/integrations/jenkins/spec/api/requests_spec.rb +57 -0
- data/customers/demo/integrations/jenkins/spec/spec_helper.rb +33 -0
- data/customers/demo/integrations/jira/process_webhook_event.rb +33 -0
- data/customers/demo/jira_mappings.rb +29 -0
- data/infrastructure/integrations/event_handler.rb +62 -0
- data/infrastructure/integrations/webhook_receiver.rb +49 -0
- data/infrastructure/shell_scripts/backup_database.sh +19 -0
- data/infrastructure/shell_scripts/create_bl_package.sh +34 -0
- data/infrastructure/shell_scripts/create_release_request.sh +34 -0
- data/infrastructure/shell_scripts/ddns.sh +10 -0
- data/infrastructure/shell_scripts/install_brpm.sh +63 -0
- data/infrastructure/shell_scripts/install_content_module.sh +66 -0
- data/infrastructure/shell_scripts/install_content_repo.sh +60 -0
- data/infrastructure/shell_scripts/install_module_from_gem.sh +80 -0
- data/infrastructure/shell_scripts/maintenance.sh +4 -0
- data/infrastructure/shell_scripts/patch_brpm.sh +90 -0
- data/infrastructure/shell_scripts/restore_database.sh +33 -0
- data/infrastructure/shell_scripts/run_event_handler.cmd +16 -0
- data/infrastructure/shell_scripts/run_event_handler.sh +20 -0
- data/infrastructure/shell_scripts/run_webhook_receiver.cmd +14 -0
- data/infrastructure/shell_scripts/run_webhook_receiver.sh +15 -0
- data/infrastructure/shell_scripts/update_content_repo.sh +21 -0
- data/infrastructure/silent_install_options_4.6.txt +93 -0
- data/infrastructure/silent_install_options_upgrade_4.6.txt +92 -0
- data/infrastructure/smtp_settings.rb +42 -0
- data/infrastructure/ssh_script_header_additions.rb +21 -0
- data/modules/ansible/automations/execute_role.rb +3 -0
- data/modules/ansible/automations/execute_role.txt +12 -0
- data/modules/ansible/config.yml +5 -0
- data/modules/ansible/lib/ansible.rb +41 -0
- data/modules/atrium_orchestrator/automations/execute_workflow.rb +12 -0
- data/modules/atrium_orchestrator/automations/execute_workflow.txt +25 -0
- data/modules/atrium_orchestrator/automations/reserve_ip_address.rb +22 -0
- data/modules/atrium_orchestrator/automations/reserve_ip_address.txt +21 -0
- data/modules/atrium_orchestrator/config.yml +7 -0
- data/modules/atrium_orchestrator/lib/ao_soap_client.rb +94 -0
- data/modules/bladelogic/automations/create_package.rb +29 -0
- data/modules/bladelogic/automations/create_package.txt +26 -0
- data/modules/bladelogic/automations/deploy_package.rb +137 -0
- data/modules/bladelogic/automations/deploy_package.txt +53 -0
- data/modules/bladelogic/config.yml +7 -0
- data/modules/bladelogic/lib/bl_rest/bsa_rest_client.rb +65 -0
- data/modules/bladelogic/lib/bl_soap/blpackage.rb +43 -0
- data/modules/bladelogic/lib/bl_soap/bsa_soap_base.rb +118 -0
- data/modules/bladelogic/lib/bl_soap/bsa_soap_client.rb +34 -0
- data/modules/bladelogic/lib/bl_soap/compliance_job.rb +155 -0
- data/modules/bladelogic/lib/bl_soap/deploy_job.rb +48 -0
- data/modules/bladelogic/lib/bl_soap/depot_group.rb +47 -0
- data/modules/bladelogic/lib/bl_soap/job.rb +376 -0
- data/modules/bladelogic/lib/bl_soap/job_group.rb +72 -0
- data/modules/bladelogic/lib/bl_soap/job_management.rb +22 -0
- data/modules/bladelogic/lib/bl_soap/job_result.rb +12 -0
- data/modules/bladelogic/lib/bl_soap/job_run.rb +271 -0
- data/modules/bladelogic/lib/bl_soap/login.rb +47 -0
- data/modules/bladelogic/lib/bl_soap/nsh_script_job.rb +14 -0
- data/modules/bladelogic/lib/bl_soap/patch_catalog.rb +178 -0
- data/modules/bladelogic/lib/bl_soap/patch_remediation_job.rb +137 -0
- data/modules/bladelogic/lib/bl_soap/patching_job.rb +250 -0
- data/modules/bladelogic/lib/bl_soap/server.rb +12 -0
- data/modules/bladelogic/lib/bl_soap/template.rb +13 -0
- data/modules/bladelogic/lib/bl_soap/utility.rb +99 -0
- data/modules/bladelogic/resource_automations/select_job.rb +33 -0
- data/modules/bladelogic/resource_automations/select_job.txt +15 -0
- data/modules/bladelogic/tests/create_package_spec.rb +28 -0
- data/modules/bladelogic/tests/deploy_package_spec.rb +23 -0
- data/modules/bladelogic/tests/spec_helper.rb +82 -0
- data/modules/brpm/automations/create_release_from_excel.rb +34 -0
- data/modules/brpm/automations/create_release_from_excel.txt +5 -0
- data/modules/brpm/automations/create_release_request.rb +100 -0
- data/modules/brpm/automations/create_release_request.txt +5 -0
- data/modules/brpm/automations/create_request.rb +73 -0
- data/modules/brpm/automations/create_request.txt +23 -0
- data/modules/brpm/automations/promote_request.rb +197 -0
- data/modules/brpm/automations/promote_request.txt +24 -0
- data/modules/brpm/automations/select_application_version.rb +22 -0
- data/modules/brpm/automations/select_application_version.txt +17 -0
- data/modules/brpm/automations/select_component_version.rb +12 -0
- data/modules/brpm/automations/select_component_version.txt +5 -0
- data/modules/brpm/automations/select_request_template.rb +6 -0
- data/modules/brpm/automations/select_request_template.txt +13 -0
- data/modules/brpm/automations/wait_for_step_in_other_request.rb +11 -0
- data/modules/brpm/automations/wait_for_step_in_other_request.txt +13 -0
- data/modules/brpm/automations/wait_till_promoted_request_is_completed.rb +9 -0
- data/modules/brpm/automations/wait_till_promoted_request_is_completed.txt +5 -0
- data/modules/brpm/config.yml +6 -0
- data/modules/brpm/lib/brpm_request.rb +207 -0
- data/modules/brpm/lib/brpm_rest.rb +312 -0
- data/modules/brpm/lib/brpm_rest_client.rb +1501 -0
- data/modules/brpm/resource_automations/select_application.rb +16 -0
- data/modules/brpm/resource_automations/select_application.txt +5 -0
- data/modules/brpm/resource_automations/select_environment.rb +14 -0
- data/modules/brpm/resource_automations/select_environment.txt +5 -0
- data/modules/brpm/resource_automations/select_request_template.rb +16 -0
- data/modules/brpm/resource_automations/select_request_template.txt +5 -0
- data/modules/brpm/resource_automations/select_step_in_request.rb +33 -0
- data/modules/brpm/resource_automations/select_step_in_request.txt +5 -0
- data/modules/brpm/sample_applications/e-finance.json +0 -0
- data/modules/brpm/tests/create_release_request_spec.rb +66 -0
- data/modules/brpm/tests/create_request_spec.rb +84 -0
- data/modules/brpm/tests/select_application_version_spec.rb +47 -0
- data/modules/brpm/tests/spec_helper.rb +63 -0
- data/modules/docker_brpm/automations/create_brpm_instance_input_params.rb +10 -0
- data/modules/docker_brpm/automations/create_brpm_instance_input_params.txt +17 -0
- data/modules/docker_brpm/automations/create_brpm_instance_one_shot.rb +60 -0
- data/modules/docker_brpm/automations/create_brpm_instance_one_shot.txt +14 -0
- data/modules/docker_brpm/automations/create_brpm_instance_show_results.rb +23 -0
- data/modules/docker_brpm/automations/create_brpm_instance_show_results.txt +13 -0
- data/modules/docker_brpm/automations/create_database.rb +24 -0
- data/modules/docker_brpm/automations/create_database.txt +3 -0
- data/modules/docker_brpm/automations/create_environment.rb +14 -0
- data/modules/docker_brpm/automations/create_environment.txt +3 -0
- data/modules/docker_brpm/automations/create_image_for_application.rb +23 -0
- data/modules/docker_brpm/automations/create_image_for_application.txt +6 -0
- data/modules/docker_brpm/automations/create_image_for_brpm_application_input_params.rb +7 -0
- data/modules/docker_brpm/automations/create_image_for_brpm_application_input_params.txt +8 -0
- data/modules/docker_brpm/automations/create_image_for_brpm_database_creator_input_params.rb +7 -0
- data/modules/docker_brpm/automations/create_image_for_brpm_database_creator_input_params.txt +8 -0
- data/modules/docker_brpm/automations/create_image_for_database_creator.rb +21 -0
- data/modules/docker_brpm/automations/create_image_for_database_creator.txt +6 -0
- data/modules/docker_brpm/automations/create_installed_component_for_application.rb +11 -0
- data/modules/docker_brpm/automations/create_installed_component_for_application.txt +3 -0
- data/modules/docker_brpm/automations/create_installed_component_for_database.rb +7 -0
- data/modules/docker_brpm/automations/create_installed_component_for_database.txt +3 -0
- data/modules/docker_brpm/automations/create_installed_component_for_database_creator.rb +8 -0
- data/modules/docker_brpm/automations/create_installed_component_for_database_creator.txt +3 -0
- data/modules/docker_brpm/automations/create_installed_component_for_utilities.rb +7 -0
- data/modules/docker_brpm/automations/create_installed_component_for_utilities.txt +3 -0
- data/modules/docker_brpm/automations/create_version_tags_for_component_in_all_envs.rb +13 -0
- data/modules/docker_brpm/automations/create_version_tags_for_component_in_all_envs.txt +6 -0
- data/modules/docker_brpm/automations/delete_brpm_instance.rb +38 -0
- data/modules/docker_brpm/automations/delete_brpm_instance.txt +8 -0
- data/modules/docker_brpm/automations/execute_test_run_in_jenkins.rb +43 -0
- data/modules/docker_brpm/automations/execute_test_run_in_jenkins.txt +13 -0
- data/modules/docker_brpm/automations/execute_test_run_in_jenkins_show_results.rb +5 -0
- data/modules/docker_brpm/automations/execute_test_run_in_jenkins_show_results.txt +9 -0
- data/modules/docker_brpm/automations/launch_create_image_for_brpm_application_request.rb +27 -0
- data/modules/docker_brpm/automations/launch_create_image_for_brpm_application_request.txt +3 -0
- data/modules/docker_brpm/automations/launch_test_run_request.rb +30 -0
- data/modules/docker_brpm/automations/launch_test_run_request.txt +14 -0
- data/modules/docker_brpm/automations/release_brpm_input_params.rb +7 -0
- data/modules/docker_brpm/automations/release_brpm_input_params.txt +8 -0
- data/modules/docker_brpm/automations/run_application_container.rb +27 -0
- data/modules/docker_brpm/automations/run_application_container.txt +3 -0
- data/modules/docker_brpm/automations/run_database_container.rb +14 -0
- data/modules/docker_brpm/automations/run_database_container.txt +3 -0
- data/modules/docker_brpm/automations/stop_application_container.rb +11 -0
- data/modules/docker_brpm/automations/stop_application_container.txt +3 -0
- data/modules/docker_brpm/automations/stop_database_container.rb +11 -0
- data/modules/docker_brpm/automations/stop_database_container.txt +3 -0
- data/modules/docker_brpm/automations/test_rest_api.rb +18 -0
- data/modules/docker_brpm/automations/test_rest_api.txt +3 -0
- data/modules/docker_brpm/automations/upgrade_database.rb +19 -0
- data/modules/docker_brpm/automations/upgrade_database.txt +8 -0
- data/modules/docker_brpm/config.yml +8 -0
- data/modules/docker_brpm/lib/docker.rb +39 -0
- data/modules/docker_brpm/lib/git.rb +16 -0
- data/modules/docker_brpm/sample_applications/dockerizedbrpm.json +0 -0
- data/modules/email/automations/send_notification.rb +48 -0
- data/modules/email/automations/send_notification.txt +27 -0
- data/modules/email/config.yml +6 -0
- data/modules/framework/automations/direct_execute.rb +10 -0
- data/modules/framework/automations/direct_execute.txt +16 -0
- data/modules/framework/automations/install_module.rb +13 -0
- data/modules/framework/automations/install_module.txt +16 -0
- data/modules/framework/bin/brpm_install +106 -0
- data/modules/framework/bin/event_handler +63 -0
- data/modules/framework/bin/webhook_receiver +49 -0
- data/modules/framework/brpm_auto.rb +307 -0
- data/modules/framework/brpm_framework.rb +88 -0
- data/modules/framework/brpm_script_executor.rb +146 -0
- data/modules/framework/config.yml +7 -0
- data/modules/framework/config/customer_include.rb +26 -0
- data/modules/framework/config/server.yml +3 -0
- data/modules/framework/customer_include_default.rb +25 -0
- data/modules/framework/lib/logging/brpm_logger.rb +39 -0
- data/modules/framework/lib/logging/logger_base.rb +36 -0
- data/modules/framework/lib/logging/simple_logger.rb +27 -0
- data/modules/framework/lib/params/all_params.rb +80 -0
- data/modules/framework/lib/params/integration_settings.rb +27 -0
- data/modules/framework/lib/params/params.rb +172 -0
- data/modules/framework/lib/params/params_base.rb +81 -0
- data/modules/framework/lib/params/request_params.rb +38 -0
- data/modules/framework/lib/resource_framework.rb +211 -0
- data/modules/framework/lib/rest_api.rb +155 -0
- data/modules/framework/lib/semaphore.rb +79 -0
- data/modules/framework/lib/utilities.rb +317 -0
- data/modules/framework/lib/version_control/git.rb +192 -0
- data/modules/framework/lib/version_control/svn.rb +221 -0
- data/modules/framework/log.html +39 -0
- data/modules/framework/tests/all_params_spec.rb +116 -0
- data/modules/framework/tests/brpm_auto_spec.rb +84 -0
- data/modules/framework/tests/customer_include/config/customer_include.rb +10 -0
- data/modules/framework/tests/customer_include/config/server.yml +3 -0
- data/modules/framework/tests/customer_include_spec.rb +29 -0
- data/modules/framework/tests/local_jirb.rb +15 -0
- data/modules/framework/tests/params_spec.rb +172 -0
- data/modules/framework/tests/request_params_spec.rb +86 -0
- data/modules/framework/tests/server_yaml_spec.rb +19 -0
- data/modules/framework/tests/spec_helper.rb +42 -0
- data/modules/framework/transport/dispatch_baa.rb +355 -0
- data/modules/framework/transport/dispatch_base.rb +345 -0
- data/modules/framework/transport/dispatch_nsh.rb +248 -0
- data/modules/framework/transport/dispatch_ssh.rb +154 -0
- data/modules/framework/transport/transport_baa.rb +1095 -0
- data/modules/framework/transport/transport_nsh.rb +359 -0
- data/modules/framework/transport/transport_ssh.rb +220 -0
- data/modules/framework/write_to.rb +1 -0
- data/modules/jenkins/automations/create_release.rb +4 -0
- data/modules/jenkins/automations/create_release.txt +23 -0
- data/modules/jenkins/automations/f2_downloadJenkinsArtifact.rb +126 -0
- data/modules/jenkins/config.yml +7 -0
- data/modules/jenkins/lib/jenkins.rb +300 -0
- data/modules/jenkins/resource_automations/f2_rsc_jenkinsJobs.rb +58 -0
- data/modules/jira/automations/add_comment.rb +4 -0
- data/modules/jira/automations/add_comment.txt +23 -0
- data/modules/jira/automations/create_release.rb +4 -0
- data/modules/jira/automations/create_release.txt +23 -0
- data/modules/jira/automations/delete_release.rb +4 -0
- data/modules/jira/automations/delete_release.txt +23 -0
- data/modules/jira/automations/transition_issue.rb +4 -0
- data/modules/jira/automations/transition_issue.txt +23 -0
- data/modules/jira/automations/transition_issues_for_request.rb +29 -0
- data/modules/jira/automations/transition_issues_for_request.txt +20 -0
- data/modules/jira/automations/transition_issues_for_run.rb +26 -0
- data/modules/jira/automations/transition_issues_for_run.txt +20 -0
- data/modules/jira/automations/update_release.rb +4 -0
- data/modules/jira/automations/update_release.txt +26 -0
- data/modules/jira/config.yml +7 -0
- data/modules/jira/lib/jira_rest_client.rb +185 -0
- data/modules/jira/tests/create_read_update_delete_release_spec.rb +39 -0
- data/modules/jira/tests/spec_helper.rb +39 -0
- data/modules/jira/tests/transition_issue_spec.rb +32 -0
- data/modules/patch_process_management/automations/execute_job/script.rb +105 -0
- data/modules/patch_process_management/automations/execute_job/wrapper.txt +39 -0
- data/modules/patch_process_management/automations/patch_analysis/script.rb +107 -0
- data/modules/patch_process_management/automations/patch_analysis/wrapper.txt +33 -0
- data/modules/patch_process_management/automations/patch_readiness/script.rb +89 -0
- data/modules/patch_process_management/automations/patch_readiness/wrapper.txt +33 -0
- data/modules/patch_process_management/automations/patch_remediation/script.rb +217 -0
- data/modules/patch_process_management/automations/patch_remediation/wrapper.txt +40 -0
- data/modules/patch_process_management/config.yml +10 -0
- data/modules/teamcity/automations/trigger_build.rb +4 -0
- data/modules/teamcity/automations/trigger_build.txt +14 -0
- data/modules/teamcity/config.yml +7 -0
- data/modules/teamcity/lib/teamcity_rest_client.rb +17 -0
- data/modules/teamcity/tests/spec_helper.rb +34 -0
- data/modules/teamcity/tests/trigger_build_spec.rb +27 -0
- data/modules/windows/automations/deploy_directory_over_windows_shares/script.rb +87 -0
- data/modules/windows/automations/deploy_directory_over_windows_shares/wrapper.txt +29 -0
- data/modules/windows/automations/deploy_file_over_windows_shares/script.rb +31 -0
- data/modules/windows/automations/deploy_file_over_windows_shares/wrapper.txt +24 -0
- data/modules/windows/config.yml +6 -0
- data/modules/windows/lib/samba.rb +29 -0
- metadata +397 -0
@@ -0,0 +1,79 @@
|
|
1
|
+
# Creates a pid-file semaphore to govern global execution
|
2
|
+
#
|
3
|
+
# ==== Attributes
|
4
|
+
#
|
5
|
+
# * +semaphore_key+ - string to name semaphore
|
6
|
+
# ==== Returns
|
7
|
+
#
|
8
|
+
# true if semaphore created, false if already exists
|
9
|
+
#
|
10
|
+
def semaphore(semaphore_key)
|
11
|
+
semaphore_dir = "#{BrpmAuto.params.automation_results_dir}/semaphores"
|
12
|
+
semaphore_name = "#{semaphore_key}.pid"
|
13
|
+
FileUtils.mkdir(semaphore_dir) unless File.exist?(semaphore_dir)
|
14
|
+
return false if File.exist?(File.join(semaphore_dir, semaphore_name))
|
15
|
+
fil = File.open(File.join(semaphore_dir, semaphore_name), "w+")
|
16
|
+
fil.puts BrpmAuto.precision_timestamp
|
17
|
+
fil.flush
|
18
|
+
fil.close
|
19
|
+
return true
|
20
|
+
end
|
21
|
+
|
22
|
+
# Clears a pid-file semaphore to govern global execution
|
23
|
+
#
|
24
|
+
# ==== Attributes
|
25
|
+
#
|
26
|
+
# * +semaphore_key+ - string to name semaphore
|
27
|
+
# ==== Returns
|
28
|
+
#
|
29
|
+
# true if semaphore deleted, false if it doesn't exist
|
30
|
+
#
|
31
|
+
def semaphore_clear(semaphore_key)
|
32
|
+
semaphore_dir = "#{BrpmAuto.params.automation_results_dir}/semaphores"
|
33
|
+
semaphore_name = "#{semaphore_key}.pid"
|
34
|
+
return false unless File.exist?(File.join(semaphore_dir, semaphore_name))
|
35
|
+
File.delete(File.join(semaphore_dir, semaphore_name))
|
36
|
+
return true
|
37
|
+
end
|
38
|
+
|
39
|
+
# Checks if a semaphore exists
|
40
|
+
#
|
41
|
+
# ==== Attributes
|
42
|
+
#
|
43
|
+
# * +semaphore_key+ - string to name semaphore
|
44
|
+
# ==== Returns
|
45
|
+
#
|
46
|
+
# true if semaphore exists, false if it doesn't exist
|
47
|
+
#
|
48
|
+
def semaphore_exists(semaphore_key)
|
49
|
+
semaphore_dir = "#{BrpmAuto.params.automation_results_dir}/semaphores"
|
50
|
+
semaphore_name = "#{semaphore_key}.pid"
|
51
|
+
return true if File.exist?(File.join(semaphore_dir, semaphore_name))
|
52
|
+
return false
|
53
|
+
end
|
54
|
+
|
55
|
+
# Waits a specified period for a semaphore to clear
|
56
|
+
# throws error after wait time if semaphore does not clear
|
57
|
+
# ==== Attributes
|
58
|
+
#
|
59
|
+
# * +semaphore_key+ - string to name semaphore
|
60
|
+
# * +wait_time+ - time in minutes before failure (default = 15mins)
|
61
|
+
# ==== Returns
|
62
|
+
#
|
63
|
+
# true if semaphore is cleared
|
64
|
+
#
|
65
|
+
def semaphore_wait(semaphore_key, wait_time = 15)
|
66
|
+
interval = 20; elapsed = 0
|
67
|
+
semaphore_dir = "#{BrpmAuto.params.automation_results_dir}/semaphores"
|
68
|
+
semaphore_name = "#{semaphore_key}.pid"
|
69
|
+
semaphore = File.join(semaphore_dir, semaphore_name)
|
70
|
+
return true if !File.exist?(semaphore)
|
71
|
+
until !File.exist?(semaphore) || (elapsed/60 > wait_time) do
|
72
|
+
sleep interval
|
73
|
+
elapsed += interval
|
74
|
+
end
|
75
|
+
if File.exist?(semaphore)
|
76
|
+
raise "ERROR: Semaphore (#{semaphore}) still exists after #{wait_time} minutes"
|
77
|
+
end
|
78
|
+
return true
|
79
|
+
end
|
@@ -0,0 +1,317 @@
|
|
1
|
+
module Utilities
|
2
|
+
|
3
|
+
EXIT_CODE_FAILURE = 'Exit_Code_Failure'
|
4
|
+
Windows = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/) unless defined?(Windows)
|
5
|
+
|
6
|
+
# Returns the dos path from a standard path
|
7
|
+
#
|
8
|
+
# ==== Attributes
|
9
|
+
#
|
10
|
+
# * +source_path+ - path in standard "/" format
|
11
|
+
# * +drive_letter+ - base drive letter if not included in path (defaults to C)
|
12
|
+
#
|
13
|
+
# ==== Returns
|
14
|
+
#
|
15
|
+
# * dos compatible path
|
16
|
+
#
|
17
|
+
def dos_path(source_path, drive_letter = "C")
|
18
|
+
path = ""
|
19
|
+
return source_path.gsub("/", "\\") if source_path.include?(":\\")
|
20
|
+
path_array = source_path.split("/")
|
21
|
+
if path_array[1].length == 1 # drive letter
|
22
|
+
path = "#{path_array[1]}:\\"
|
23
|
+
path += path_array[2..-1].join("\\")
|
24
|
+
else
|
25
|
+
path = "#{drive_letter}:\\"
|
26
|
+
path += path_array[1..-1].join("\\")
|
27
|
+
end
|
28
|
+
path
|
29
|
+
end
|
30
|
+
|
31
|
+
# Executes a command via shell
|
32
|
+
#
|
33
|
+
# ==== Attributes
|
34
|
+
#
|
35
|
+
# * +command+ - command to execute on command line
|
36
|
+
# ==== Returns
|
37
|
+
#
|
38
|
+
# * command_run hash {stdout => <results>, stderr => any errors, pid => process id, status => exit_code}
|
39
|
+
def execute_shell(command, sensitive_data = nil)
|
40
|
+
escaped_command = command.gsub("\\", "\\\\")
|
41
|
+
|
42
|
+
loggable_command = BrpmAuto.privatize(escaped_command, sensitive_data)
|
43
|
+
BrpmAuto.log "Executing '#{loggable_command}'..."
|
44
|
+
|
45
|
+
cmd_result = {"stdout" => "","stderr" => "", "pid" => "", "status" => 1}
|
46
|
+
|
47
|
+
output_dir = File.join(BrpmAuto.params.output_dir,"#{precision_timestamp}")
|
48
|
+
errfile = "#{output_dir}_stderr.txt"
|
49
|
+
complete_command = "#{escaped_command} 2>#{errfile}" unless Windows
|
50
|
+
fil = File.open(errfile, "w+")
|
51
|
+
fil.close
|
52
|
+
|
53
|
+
begin
|
54
|
+
cmd_result["stdout"] = `#{complete_command}`
|
55
|
+
status = $?
|
56
|
+
cmd_result["pid"] = status.pid
|
57
|
+
cmd_result["status"] = status.to_i
|
58
|
+
|
59
|
+
fil = File.open(errfile)
|
60
|
+
stderr = fil.read
|
61
|
+
fil.close
|
62
|
+
|
63
|
+
if stderr.length > 2
|
64
|
+
BrpmAuto.log "Command generated an error: #{stderr}"
|
65
|
+
cmd_result["stderr"] = stderr
|
66
|
+
end
|
67
|
+
rescue Exception => e
|
68
|
+
BrpmAuto.log "Command generated an error: #{e.message}"
|
69
|
+
BrpmAuto.log "Back trace:\n#{e.backtrace}"
|
70
|
+
|
71
|
+
cmd_result["status"] = -1
|
72
|
+
cmd_result["stderr"] = "ERROR\n#{e.message}"
|
73
|
+
end
|
74
|
+
|
75
|
+
File.delete(errfile)
|
76
|
+
|
77
|
+
cmd_result
|
78
|
+
end
|
79
|
+
|
80
|
+
# Returns a timestamp to the thousanth of a second
|
81
|
+
#
|
82
|
+
# ==== Returns
|
83
|
+
#
|
84
|
+
# string timestamp 20140921153010456
|
85
|
+
#
|
86
|
+
def precision_timestamp
|
87
|
+
Time.now.strftime("%Y%m%d%H%M%S%L")
|
88
|
+
end
|
89
|
+
|
90
|
+
# Provides a simple failsafe for working with hash options
|
91
|
+
# returns "" if the option doesn't exist or is blank
|
92
|
+
# ==== Attributes
|
93
|
+
#
|
94
|
+
# * +options+ - the hash
|
95
|
+
# * +key+ - key to find in options
|
96
|
+
# * +default_value+ - if entered will be returned if the option doesn't exist or is blank
|
97
|
+
def get_option(options, key, default_value = "")
|
98
|
+
result = options.has_key?(key) ? options[key] : nil
|
99
|
+
result = default_value if result.nil? || result == ""
|
100
|
+
result
|
101
|
+
end
|
102
|
+
|
103
|
+
# Throws an error if an option is missing
|
104
|
+
# great for checking if properties exist
|
105
|
+
#
|
106
|
+
# ==== Attributes
|
107
|
+
#
|
108
|
+
# * +options+ - the options hash
|
109
|
+
# * +key+ - key to find
|
110
|
+
def required_option(options, key)
|
111
|
+
result = get_option(options, key)
|
112
|
+
raise ArgumentError, "Missing required option: #{key}" if result == ""
|
113
|
+
result
|
114
|
+
end
|
115
|
+
|
116
|
+
# Splits the server and path from an nsh path
|
117
|
+
# returns same path if no server prepended
|
118
|
+
# ==== Attributes
|
119
|
+
#
|
120
|
+
# * +path+ - nsh path
|
121
|
+
# ==== Returns
|
122
|
+
#
|
123
|
+
# array [server, path] server is blank if not present
|
124
|
+
#
|
125
|
+
def split_nsh_path(path)
|
126
|
+
result = ["",path]
|
127
|
+
result[0] = path.split("/")[2] if path.start_with?("//")
|
128
|
+
result[1] = "/#{path.split("/")[3..-1].join("/")}" if path.start_with?("//")
|
129
|
+
result
|
130
|
+
end
|
131
|
+
|
132
|
+
# Reads the Shebang in a shell script
|
133
|
+
# Supports deep format which can include wrapper information
|
134
|
+
# ==== Attributes
|
135
|
+
#
|
136
|
+
# * +os_platform+ - windows or linux
|
137
|
+
# * +action_txt+ - the body of the shell script (action)
|
138
|
+
# ==== Returns
|
139
|
+
#
|
140
|
+
# shebang hash e.g. {"ext" => ".bat", "cmd" => "cmd /c", "shebang" => "#![.bat]cmd /c "}
|
141
|
+
#
|
142
|
+
def read_shebang(os_platform, action_txt)
|
143
|
+
if os_platform.downcase =~ /win/
|
144
|
+
result = {"ext" => ".bat", "cmd" => "cmd /c", "shebang" => ""}
|
145
|
+
else
|
146
|
+
result = {"ext" => ".sh", "cmd" => "/bin/bash ", "shebang" => ""}
|
147
|
+
end
|
148
|
+
if action_txt.include?("#![") # Custom shebang
|
149
|
+
shebang = action_txt.scan(/\#\!.*/).first
|
150
|
+
result["shebang"] = shebang
|
151
|
+
items = shebang.scan(/\#\!\[.*\]/)
|
152
|
+
if items.size > 0
|
153
|
+
ext = items[0].gsub("#![","").gsub("]","")
|
154
|
+
result["ext"] = ext if ext.start_with?(".")
|
155
|
+
result["cmd"] = shebang.gsub(items[0],"").strip
|
156
|
+
else
|
157
|
+
result["cmd"] = shebang
|
158
|
+
end
|
159
|
+
elsif action_txt.include?("#!/") # Basic shebang
|
160
|
+
result["shebang"] = "standard"
|
161
|
+
else # no shebang
|
162
|
+
result["shebang"] = "none"
|
163
|
+
end
|
164
|
+
result
|
165
|
+
end
|
166
|
+
|
167
|
+
# Takes the command result from run command and build a pretty display
|
168
|
+
#
|
169
|
+
# ==== Attributes
|
170
|
+
#
|
171
|
+
# * +cmd_result+ - the command result hash
|
172
|
+
# ==== Returns
|
173
|
+
#
|
174
|
+
# * formatted text
|
175
|
+
def display_result(cmd_result)
|
176
|
+
result = "Process: #{cmd_result["pid"]}\nSTDOUT:\n#{cmd_result["stdout"]}\n"
|
177
|
+
result = "STDERR:\n #{cmd_result["stderr"]}\n#{result}" if cmd_result["stderr"].length > 2
|
178
|
+
result += "#{EXIT_CODE_FAILURE} Command returned: #{cmd_result["status"]}" if cmd_result["status"] != 0
|
179
|
+
result
|
180
|
+
end
|
181
|
+
|
182
|
+
# Looks for terms in the results and builds an exit message
|
183
|
+
# returns status message with "Command_Failed if the status fails"
|
184
|
+
# ==== Attributes
|
185
|
+
# * +results+ - the text to analyze for success
|
186
|
+
# * +success_terms+ - the term or terms (use | or & for and and or with multiple terms)
|
187
|
+
# * +fail_now+ - if set to true will throw an error if a term is not found
|
188
|
+
# ==== Returns
|
189
|
+
# * +text+ - summary of success terms
|
190
|
+
#
|
191
|
+
def verify_success_terms(results, success_terms, fail_now = false, quiet = false)
|
192
|
+
results.split("\n").each{|line| exit_status = line if line.start_with?("EXIT_CODE:") }
|
193
|
+
if success_terms != ""
|
194
|
+
exit_status = []
|
195
|
+
c_type = success_terms.include?("|") ? "or" : "and"
|
196
|
+
success = [success_terms] if !success_terms.include?("|") || !success_terms.include?("&")
|
197
|
+
success = success_terms.split("|") if success_terms.include?("|")
|
198
|
+
success = success_terms.split("&") if success_terms.include?("&")
|
199
|
+
success.each do |term|
|
200
|
+
if results.include?(term)
|
201
|
+
exit_status << "Success - found term: #{term}"
|
202
|
+
else
|
203
|
+
exit_status << "Command_Failed: term not found: #{term}"
|
204
|
+
end
|
205
|
+
end
|
206
|
+
status = exit_status.join(", ")
|
207
|
+
status.gsub!("Command_Failed:", "") if status.include?("Success") if c_type == "or"
|
208
|
+
else
|
209
|
+
status = "Success (because nothing was tested)"
|
210
|
+
end
|
211
|
+
log status unless quiet
|
212
|
+
raise "ERROR: success term not found" if fail_now && status.include?("Command_Failed")
|
213
|
+
status
|
214
|
+
end
|
215
|
+
|
216
|
+
# Checks/Creates a staging directory
|
217
|
+
#
|
218
|
+
# ==== Attributes
|
219
|
+
#
|
220
|
+
# * +force+ - forces creation of the path if it doesnt exist
|
221
|
+
# ==== Returns
|
222
|
+
#
|
223
|
+
# staging path or ERROR_ if force is false and path does not exist
|
224
|
+
#
|
225
|
+
def get_staging_dir(version, force = false)
|
226
|
+
staging_path = defined?(RPM_STAGING_PATH) ? RPM_STAGING_PATH : File.join(BrpmAuto.all_params["SS_automation_results_dir"],"staging")
|
227
|
+
pattern = File.join(staging_path, "#{Time.now.year.to_s}", path_safe(get_param("SS_application")), path_safe(get_param("SS_component")), path_safe(version))
|
228
|
+
if force
|
229
|
+
FileUtils.mkdir_p(pattern)
|
230
|
+
else
|
231
|
+
return pattern if File.exist?(pattern) # Cannot stage the same files twice
|
232
|
+
return "ERROR_#{pattern}"
|
233
|
+
end
|
234
|
+
pattern
|
235
|
+
end
|
236
|
+
|
237
|
+
# Returns a version of the string safe for a filname or path
|
238
|
+
def path_safe(txt)
|
239
|
+
txt.gsub(" ", "_").gsub(/\,|\[|\]/,"")
|
240
|
+
end
|
241
|
+
|
242
|
+
# DEPRECATED - use substitute_tokens instead (token has the format rpm{MY_TOKEN} instead of $${MY_TOKEN} to avid interference with shell variables)
|
243
|
+
def get_keyword_items(script_content = nil)
|
244
|
+
result = {}
|
245
|
+
content = script_content unless script_content.nil?
|
246
|
+
content = File.open(BrpmAuto.all_params["SS_script_file"]).read if script_content.nil?
|
247
|
+
KEYWORD_SWITCHES.each do |keyword|
|
248
|
+
reg = /\$\$\{#{keyword}\=.*\}\$\$/
|
249
|
+
items = content.scan(reg)
|
250
|
+
items.each do |item|
|
251
|
+
result[keyword] = item.gsub("$${#{keyword}=","").gsub("}$$","").chomp("\"").gsub(/^\"/,"")
|
252
|
+
end
|
253
|
+
end
|
254
|
+
result
|
255
|
+
end
|
256
|
+
|
257
|
+
def windows?
|
258
|
+
Windows
|
259
|
+
end
|
260
|
+
|
261
|
+
def privatize(expression, sensitive_data = BrpmAuto.params.private_params.values)
|
262
|
+
unless sensitive_data.nil? or sensitive_data.empty?
|
263
|
+
sensitive_data = [sensitive_data] if sensitive_data.kind_of?(String)
|
264
|
+
|
265
|
+
sensitive_data.each do |sensitive_string|
|
266
|
+
expression = expression.gsub(sensitive_string, "********")
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
expression
|
271
|
+
end
|
272
|
+
|
273
|
+
def substitute_tokens(expression, params = nil)
|
274
|
+
return expression if expression.nil? || !expression.kind_of?(String)
|
275
|
+
|
276
|
+
searchable_params = params || @all_params
|
277
|
+
|
278
|
+
found_token = expression.match('rpm{[^{}]*}')
|
279
|
+
while ! found_token.nil? do
|
280
|
+
raise "Property #{found_token[0][4..-2]} doesn't exist" if searchable_params[found_token[0][4..-2]].nil?
|
281
|
+
expression = expression.sub(found_token[0],searchable_params[found_token[0][4..-2]])
|
282
|
+
found_token = expression.match('rpm{[^{}]*}')
|
283
|
+
end
|
284
|
+
return expression
|
285
|
+
end
|
286
|
+
|
287
|
+
def first_defined(first, second)
|
288
|
+
if first and ! first.empty?
|
289
|
+
return first
|
290
|
+
else
|
291
|
+
return second
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
private
|
296
|
+
|
297
|
+
#TODO: still needed? the framework's error handling should take care of this already
|
298
|
+
def exit_code_failure
|
299
|
+
return "" if Windows
|
300
|
+
size_ = EXIT_CODE_FAILURE.size
|
301
|
+
exit_code_failure_first_part = EXIT_CODE_FAILURE[0..3]
|
302
|
+
exit_code_failure_second_part = EXIT_CODE_FAILURE[4..size_]
|
303
|
+
BrpmAuto.all_params['ignore_exit_codes'] == 'yes' ?
|
304
|
+
'' :
|
305
|
+
"; if [ $? -ne 0 ]; then first_part=#{exit_code_failure_first_part}; echo \"${first_part}#{exit_code_failure_second_part}\"; fi;"
|
306
|
+
end
|
307
|
+
|
308
|
+
def url_encode(name)
|
309
|
+
name.gsub(" ","%20").gsub("/","%2F").gsub("?","%3F")
|
310
|
+
end
|
311
|
+
|
312
|
+
def touch_file(file_path)
|
313
|
+
fil = File.open(file_path,"w+")
|
314
|
+
fil.close
|
315
|
+
file_path
|
316
|
+
end
|
317
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
# Base class for working with Git
|
4
|
+
class Git
|
5
|
+
|
6
|
+
# Initializes an instance of the class
|
7
|
+
#
|
8
|
+
# ==== Attributes
|
9
|
+
#
|
10
|
+
# * +git+ - path to the git executable
|
11
|
+
# * +options+ - hash of options includes:
|
12
|
+
# url - url for svn repository
|
13
|
+
# base_path - path for the local repository
|
14
|
+
# username - repository user username
|
15
|
+
# password - repository user password
|
16
|
+
# verbose - true for verbose output
|
17
|
+
# repository - name of remote git repository (default = origin)
|
18
|
+
# artifact_path - path in repository for artifacts (default = .)
|
19
|
+
# branch - scm branch (default = master)
|
20
|
+
# simulate - simulate command - echo it (default = false)
|
21
|
+
# output_file - file for logging results (default = step output file)
|
22
|
+
#
|
23
|
+
def initialize(git, options, compat_options = {})
|
24
|
+
self.extend Utilities
|
25
|
+
if options.has_key?("SS_output_dir")
|
26
|
+
BrpmAuto.log "Load for this class has changed, no longer necessary to send params as 2nd argument"
|
27
|
+
options = compat_options
|
28
|
+
end
|
29
|
+
@url = get_option(options,"url")
|
30
|
+
@base_path = get_option(options,"base_path")
|
31
|
+
user = get_option(options,"username")
|
32
|
+
password = get_option(options,"password")
|
33
|
+
@verbose = get_option(options,"verbose", false)
|
34
|
+
@artifact_path = get_option(options,"artifact_path")
|
35
|
+
@simulate = get_option(options,"simulate", false)
|
36
|
+
update_repo_info(options)
|
37
|
+
if user != "" && password != ""
|
38
|
+
@credential = " --username #{user} --password #{password}"
|
39
|
+
else
|
40
|
+
@credential = ""
|
41
|
+
end
|
42
|
+
super(params)
|
43
|
+
@git = git
|
44
|
+
end
|
45
|
+
|
46
|
+
# Updates repository info from options
|
47
|
+
#
|
48
|
+
# ==== Attributes
|
49
|
+
#
|
50
|
+
# * +options+ - hash of options, keys [repository, branch]
|
51
|
+
# ==== Returns
|
52
|
+
#
|
53
|
+
# * command output
|
54
|
+
def update_repo_info(options)
|
55
|
+
@repo = get_option(options,"repository","origin")
|
56
|
+
@branch = get_option(options,"branch","master")
|
57
|
+
end
|
58
|
+
|
59
|
+
# Performs a GIT checkout or initialize repository
|
60
|
+
#
|
61
|
+
# ==== Attributes
|
62
|
+
#
|
63
|
+
# * +init+ - true to initilize the checkout and local repo
|
64
|
+
# * +options+ - hash of options, keys [repository, branch, revision, tag]
|
65
|
+
# ==== Returns
|
66
|
+
#
|
67
|
+
# * command output
|
68
|
+
def checkout(init = false, options = {})
|
69
|
+
update_repo_info(options)
|
70
|
+
if init
|
71
|
+
cmd = "#{@git} clone #{@url} #{@credential}"
|
72
|
+
process_cmd(cmd)
|
73
|
+
cmd = "#{@git} checkout #{@branch}"
|
74
|
+
else
|
75
|
+
revision = get_option(options,"revision")
|
76
|
+
tag = get_option(options,"tag")
|
77
|
+
if revision != ""
|
78
|
+
cmd = "#{@git} checkout #{revision}"
|
79
|
+
elsif tag != ""
|
80
|
+
cmd = "#{@git} checkout tags/#{tag}"
|
81
|
+
else
|
82
|
+
cmd = "#{@git} pull #{@repo} #{@branch}"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
process_cmd(cmd)
|
86
|
+
end
|
87
|
+
|
88
|
+
# Performs an GIT commit
|
89
|
+
#
|
90
|
+
# ==== Attributes
|
91
|
+
#
|
92
|
+
# * +message+ - commit string
|
93
|
+
# * +options+ - hash of options, keys [repository, branch, push_to_repository]
|
94
|
+
# ==== Returns
|
95
|
+
#
|
96
|
+
# * command output
|
97
|
+
def commit(message = "Automation pushed changes", options = {})
|
98
|
+
update_repo_info(options)
|
99
|
+
push_to_repo = get_option(options,"push_to_repository", true)
|
100
|
+
cmd = "#{@git} commit -a -m \"#{message}\""
|
101
|
+
result = process_cmd(cmd)
|
102
|
+
cmd = "#{@git} push #{repo} #{branch}" if push_to_repo
|
103
|
+
result += process_cmd if push_to_repo
|
104
|
+
result
|
105
|
+
end
|
106
|
+
|
107
|
+
# Performs an git tag
|
108
|
+
#
|
109
|
+
# ==== Attributes
|
110
|
+
#
|
111
|
+
# * +tag_name+ - name for tag
|
112
|
+
# * +message+ - message to add to tag
|
113
|
+
# * +options+ - hash of options, keys [repository, branch, push_to_repository, tag_path]
|
114
|
+
#
|
115
|
+
# ==== Returns
|
116
|
+
#
|
117
|
+
# * command output
|
118
|
+
def tag(tag_name, message, options = {})
|
119
|
+
update_repo_info(options)
|
120
|
+
tag_path = get_option(options,"push_to_repository", true)
|
121
|
+
push_to_repo = get_option(options,"tag_path")
|
122
|
+
cmd = "#{@git} tag -a #{tag_path} -m \"#{message}\""
|
123
|
+
result = process_cmd(cmd)
|
124
|
+
cmd = "#{@git} push #{repo} #{branch}" if push_to_repo
|
125
|
+
result += process_cmd if push_to_repo
|
126
|
+
result
|
127
|
+
end
|
128
|
+
|
129
|
+
# Performs an svn statud
|
130
|
+
#
|
131
|
+
# ==== Returns
|
132
|
+
#
|
133
|
+
# * command output
|
134
|
+
def status
|
135
|
+
process_cmd "#{@git} status"
|
136
|
+
end
|
137
|
+
|
138
|
+
# Adds any new files in the local repo to the git commit list
|
139
|
+
# note: you need to commit after adding files
|
140
|
+
#
|
141
|
+
# ==== Attributes
|
142
|
+
#
|
143
|
+
# * +exclude_regex+ - regex to filter add files (file !=~ filter)
|
144
|
+
#
|
145
|
+
# ==== Returns
|
146
|
+
#
|
147
|
+
# * command output
|
148
|
+
def add_files(exclude_regex = "")
|
149
|
+
result = status
|
150
|
+
lines = result.split("\n")
|
151
|
+
ipos = lines.index("Untracked files:")
|
152
|
+
unless ipos.nil?
|
153
|
+
files = lines[(ipos + 2)..-3]
|
154
|
+
files.each do |item|
|
155
|
+
unless File.basename.start_with?(".")
|
156
|
+
cmd = "#{@git} add #{item}"
|
157
|
+
if exclude == ""
|
158
|
+
result += process_cmd(cmd)
|
159
|
+
else
|
160
|
+
result += process_cmd(cmd) unless file =~ /#{exclude}/
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
result += status
|
166
|
+
result
|
167
|
+
end
|
168
|
+
|
169
|
+
private
|
170
|
+
|
171
|
+
def process_cmd(cmd)
|
172
|
+
goto_base
|
173
|
+
res = execute_shell(cmd) unless @simulate
|
174
|
+
BrpmAuto.log cmd if @verbose || @simulate
|
175
|
+
@simulate ? "ok" : display_result(res)
|
176
|
+
end
|
177
|
+
|
178
|
+
def goto_base
|
179
|
+
@pwd = FileUtils.pwd
|
180
|
+
goto_path = @base_path
|
181
|
+
FileUtils.cd(goto_path, :verbose => true) if @verbose
|
182
|
+
FileUtils.cd(goto_path) unless @verbose
|
183
|
+
end
|
184
|
+
|
185
|
+
def git_errors?(output)
|
186
|
+
svn_terms = ["403 Forbidden", "SSL error code", "moorrreee"]
|
187
|
+
found = output.scan(/#{svn_terms.join("|")}/)
|
188
|
+
found.size > 0
|
189
|
+
end
|
190
|
+
|
191
|
+
end
|
192
|
+
|