openshift-origin-controller 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYRIGHT +1 -0
- data/Gemfile +4 -0
- data/LICENSE +12 -0
- data/README.md +3 -0
- data/Rakefile +9 -0
- data/app/controllers/app_events_controller.rb +115 -0
- data/app/controllers/application_templates_controller.rb +19 -0
- data/app/controllers/applications_controller.rb +214 -0
- data/app/controllers/base_controller.rb +367 -0
- data/app/controllers/cartridges_controller.rb +48 -0
- data/app/controllers/descriptors_controller.rb +23 -0
- data/app/controllers/dns_resolvable_controller.rb +35 -0
- data/app/controllers/domains_controller.rb +156 -0
- data/app/controllers/emb_cart_controller.rb +276 -0
- data/app/controllers/emb_cart_events_controller.rb +52 -0
- data/app/controllers/environment_controller.rb +11 -0
- data/app/controllers/estimates_controller.rb +71 -0
- data/app/controllers/gear_groups_controller.rb +53 -0
- data/app/controllers/gears_controller.rb +70 -0
- data/app/controllers/keys_controller.rb +96 -0
- data/app/controllers/legacy_broker_controller.rb +510 -0
- data/app/controllers/quickstarts_controller.rb +29 -0
- data/app/controllers/user_controller.rb +38 -0
- data/app/helpers/cartridge_helper.rb +25 -0
- data/app/helpers/legacy_broker_helper.rb +21 -0
- data/app/helpers/user_action_logger.rb +38 -0
- data/app/models/application.rb +1718 -0
- data/app/models/application_template.rb +27 -0
- data/app/models/cartridge_cache.rb +51 -0
- data/app/models/cloud_user.rb +334 -0
- data/app/models/component_instance.rb +228 -0
- data/app/models/connection_endpoint.rb +10 -0
- data/app/models/district.rb +210 -0
- data/app/models/domain.rb +234 -0
- data/app/models/gear.rb +376 -0
- data/app/models/group_instance.rb +306 -0
- data/app/models/key.rb +20 -0
- data/app/models/legacy_reply.rb +15 -0
- data/app/models/legacy_request.rb +126 -0
- data/app/models/link.rb +11 -0
- data/app/models/message.rb +10 -0
- data/app/models/name_server_cache.rb +46 -0
- data/app/models/optional_param.rb +12 -0
- data/app/models/param.rb +13 -0
- data/app/models/remote_job.rb +57 -0
- data/app/models/rest_application.rb +126 -0
- data/app/models/rest_application10.rb +106 -0
- data/app/models/rest_application12.rb +124 -0
- data/app/models/rest_application_estimate.rb +12 -0
- data/app/models/rest_application_template.rb +20 -0
- data/app/models/rest_cartridge10.rb +41 -0
- data/app/models/rest_cartridge11.rb +151 -0
- data/app/models/rest_domain.rb +43 -0
- data/app/models/rest_domain10.rb +42 -0
- data/app/models/rest_estimates.rb +16 -0
- data/app/models/rest_gear.rb +14 -0
- data/app/models/rest_gear_group.rb +26 -0
- data/app/models/rest_key.rb +24 -0
- data/app/models/rest_reply.rb +31 -0
- data/app/models/rest_user.rb +43 -0
- data/app/models/result_io.rb +67 -0
- data/app/models/usage_record.rb +37 -0
- data/app/models/validators/app_validator.rb +30 -0
- data/app/models/validators/key_validator.rb +30 -0
- data/app/models/validators/namespace_validator.rb +18 -0
- data/config/routes.rb +36 -0
- data/lib/controller_engine.rb +7 -0
- data/lib/openshift-origin-controller.rb +14 -0
- data/lib/openshift/application_container_proxy.rb +241 -0
- data/lib/openshift/auth_service.rb +101 -0
- data/lib/openshift/data_store.rb +33 -0
- data/lib/openshift/dns_service.rb +41 -0
- data/lib/openshift/mongo_data_store.rb +671 -0
- data/openshift-origin-controller.gemspec +42 -0
- data/rubygem-openshift-origin-controller.spec +274 -0
- data/test/cucumber/application-estimate.feature +25 -0
- data/test/cucumber/cartridge-10gen-mms-agent.feature +28 -0
- data/test/cucumber/cartridge-cron.feature +32 -0
- data/test/cucumber/cartridge-haproxy.feature +31 -0
- data/test/cucumber/cartridge-jenkins-build.feature +12 -0
- data/test/cucumber/cartridge-jenkins-client.feature +10 -0
- data/test/cucumber/cartridge-lifecycle-diy.feature +21 -0
- data/test/cucumber/cartridge-lifecycle-jbossas.feature +61 -0
- data/test/cucumber/cartridge-lifecycle-jbosseap.feature +61 -0
- data/test/cucumber/cartridge-lifecycle-jbossews10.feature +61 -0
- data/test/cucumber/cartridge-lifecycle-jenkins.feature +41 -0
- data/test/cucumber/cartridge-lifecycle-nodejs.feature +59 -0
- data/test/cucumber/cartridge-lifecycle-perl.feature +40 -0
- data/test/cucumber/cartridge-lifecycle-php.feature +106 -0
- data/test/cucumber/cartridge-lifecycle-python.feature +40 -0
- data/test/cucumber/cartridge-lifecycle-ruby18.feature +49 -0
- data/test/cucumber/cartridge-lifecycle-ruby19.feature +41 -0
- data/test/cucumber/cartridge-mongodb.feature +31 -0
- data/test/cucumber/cartridge-mysql.feature +30 -0
- data/test/cucumber/cartridge-php.feature +14 -0
- data/test/cucumber/cartridge-phpmyadmin.feature +32 -0
- data/test/cucumber/cartridge-postgresql.feature +32 -0
- data/test/cucumber/cartridge-runtime-extended-db.feature +64 -0
- data/test/cucumber/cartridge-runtime-extended-jboss.feature +24 -0
- data/test/cucumber/cartridge-runtime-extended-nodejs.feature +21 -0
- data/test/cucumber/cartridge-runtime-extended-perl.feature +18 -0
- data/test/cucumber/cartridge-runtime-extended-php.feature +19 -0
- data/test/cucumber/cartridge-runtime-extended-python.feature +18 -0
- data/test/cucumber/cartridge-runtime-extended-ruby.feature +22 -0
- data/test/cucumber/cartridge-runtime-standard-diy.feature +6 -0
- data/test/cucumber/cartridge-runtime-standard-jbossas.feature +7 -0
- data/test/cucumber/cartridge-runtime-standard-jbosseap.feature +7 -0
- data/test/cucumber/cartridge-runtime-standard-jbossews10.feature +7 -0
- data/test/cucumber/cartridge-runtime-standard-jenkins.feature +8 -0
- data/test/cucumber/cartridge-runtime-standard-nodejs.feature +7 -0
- data/test/cucumber/cartridge-runtime-standard-perl.feature +6 -0
- data/test/cucumber/cartridge-runtime-standard-php.feature +6 -0
- data/test/cucumber/cartridge-runtime-standard-python.feature +6 -0
- data/test/cucumber/cartridge-runtime-standard-ruby.feature +19 -0
- data/test/cucumber/cartridge-switchyard.feature +36 -0
- data/test/cucumber/descriptor.feature +40 -0
- data/test/cucumber/embedded.feature +44 -0
- data/test/cucumber/idler.feature +75 -0
- data/test/cucumber/misc/descriptor/manifest.yml +22 -0
- data/test/cucumber/misc/php/db_test.php +21 -0
- data/test/cucumber/openshift-node.feature +21 -0
- data/test/cucumber/rest-application-templates.feature +31 -0
- data/test/cucumber/rest-applications.feature +431 -0
- data/test/cucumber/rest-cartridge-types.feature +16 -0
- data/test/cucumber/rest-domains.feature +276 -0
- data/test/cucumber/rest-gears.feature +38 -0
- data/test/cucumber/rest-keys.feature +247 -0
- data/test/cucumber/rest-quickstarts.feature +27 -0
- data/test/cucumber/rest-workflow.feature +64 -0
- data/test/cucumber/step_definitions/api_steps.rb +369 -0
- data/test/cucumber/step_definitions/application-estimate-steps.rb +51 -0
- data/test/cucumber/step_definitions/application_steps.rb +215 -0
- data/test/cucumber/step_definitions/cartridge-10gen-mms-agent_steps.rb +11 -0
- data/test/cucumber/step_definitions/cartridge-cron_steps.rb +51 -0
- data/test/cucumber/step_definitions/cartridge-haproxy_steps.rb +30 -0
- data/test/cucumber/step_definitions/cartridge-jenkins_steps.rb +93 -0
- data/test/cucumber/step_definitions/cartridge-lifecycle-nodejs_steps.rb +30 -0
- data/test/cucumber/step_definitions/cartridge-mongodb_steps.rb +60 -0
- data/test/cucumber/step_definitions/cartridge-mysql_steps.rb +56 -0
- data/test/cucumber/step_definitions/cartridge-php_steps.rb +72 -0
- data/test/cucumber/step_definitions/cartridge-postgresql_steps.rb +59 -0
- data/test/cucumber/step_definitions/cartridge-switchyard_steps.rb +29 -0
- data/test/cucumber/step_definitions/client_steps.rb +12 -0
- data/test/cucumber/step_definitions/descriptor_step.rb +32 -0
- data/test/cucumber/step_definitions/idler_steps.rb +37 -0
- data/test/cucumber/step_definitions/node_steps.rb +203 -0
- data/test/cucumber/step_definitions/runtime_steps.rb +547 -0
- data/test/cucumber/step_definitions/runtime_url_steps.rb +46 -0
- data/test/cucumber/step_definitions/trap-user-extended_steps.rb +14 -0
- data/test/cucumber/step_definitions/trap-user_steps.rb +58 -0
- data/test/cucumber/support/00_setup_helper.rb +106 -0
- data/test/cucumber/support/app_helper.rb +243 -0
- data/test/cucumber/support/assertions.rb +52 -0
- data/test/cucumber/support/command_helper.rb +453 -0
- data/test/cucumber/support/dns_helper.rb +54 -0
- data/test/cucumber/support/env.rb +5 -0
- data/test/cucumber/support/process_helper.rb +44 -0
- data/test/cucumber/support/runtime_support.rb +440 -0
- data/test/cucumber/support/unused.rb +27 -0
- data/test/cucumber/support/user_helper.rb +37 -0
- data/test/cucumber/trap-user-extended.feature +53 -0
- data/test/cucumber/trap-user.feature +34 -0
- data/test/ddns/1.168.192-rev.db.init +13 -0
- data/test/ddns/HOWTO.txt +207 -0
- data/test/ddns/Kexample.com.+157+06142.key +1 -0
- data/test/ddns/Kexample.com.+157+06142.private +7 -0
- data/test/ddns/authconfig.rb +14 -0
- data/test/ddns/example.com.db.init +23 -0
- data/test/ddns/example.com.key +4 -0
- data/test/ddns/named.ca +52 -0
- data/test/ddns/named.conf +48 -0
- data/test/ddns/named.empty +10 -0
- data/test/ddns/named.localhost +10 -0
- data/test/ddns/named.loopback +11 -0
- data/test/ddns/named.rfc1912.zones +42 -0
- data/test/ddns/named.root.key +5 -0
- data/test/ddns/named_service.rb +127 -0
- data/test/unit/bind_dns_service_test.rb +167 -0
- data/test/unit/broker_auth_test.rb +28 -0
- metadata +545 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
Then /^the web console for the metrics\-([\d\.]+) cartridge is( not)? accessible$/ do |version, negate|
|
|
2
|
+
steps %Q{
|
|
3
|
+
Then the web console for the metrics-#{version} cartridge at /read.php is#{negate} accessible
|
|
4
|
+
}
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
Then /^the web console for the rockmongo\-([\d\.]+) cartridge is( not)? accessible$/ do |version, negate|
|
|
8
|
+
steps %Q{
|
|
9
|
+
Then the web console for the rockmongo-#{version} cartridge at /js/collection.js is#{negate} accessible
|
|
10
|
+
}
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
Then /^the web console for the phpmyadmin\-([\d\.]+) cartridge is( not)? accessible$/ do |version, negate|
|
|
14
|
+
steps %Q{
|
|
15
|
+
Then the web console for the phpmyadmin-#{version} cartridge at /js/sql.js is#{negate} accessible
|
|
16
|
+
}
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
When /^I run the health\-check for the ([^ ]+) cartridge$/ do | type |
|
|
20
|
+
host = "#{@app.name}-#{@account.domain}.dev.rhcloud.com"
|
|
21
|
+
|
|
22
|
+
url = case type
|
|
23
|
+
when 'perl-5.10'
|
|
24
|
+
"health_check.pl"
|
|
25
|
+
when 'php-5.3'
|
|
26
|
+
"health_check.php"
|
|
27
|
+
else
|
|
28
|
+
"health"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Use curl to hit the app, causing restorer to turn it back on.
|
|
32
|
+
command = "/usr/bin/curl -k -H 'Host: #{host}' -s http://localhost/#{url}"
|
|
33
|
+
output = run_stdout command
|
|
34
|
+
output.chomp!
|
|
35
|
+
|
|
36
|
+
OpenShift::timeout(60) do
|
|
37
|
+
while output != '1'
|
|
38
|
+
output = run_stdout command
|
|
39
|
+
output.chomp!
|
|
40
|
+
$logger.info("Idler waiting for httpd graceful to finish. #{host}")
|
|
41
|
+
sleep 1
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
output.should == '1'
|
|
46
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
When /^I (start|stop) the application using ctl_all via rhcsh$/ do |action|
|
|
2
|
+
cmd = case action
|
|
3
|
+
when 'start'
|
|
4
|
+
ssh_command("rhcsh ctl_all start")
|
|
5
|
+
when 'stop'
|
|
6
|
+
ssh_command("rhcsh ctl_all stop")
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
$logger.debug "Running #{cmd}"
|
|
10
|
+
|
|
11
|
+
output = `#{cmd}`
|
|
12
|
+
|
|
13
|
+
$logger.debug "Output: #{output}"
|
|
14
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require 'pty'
|
|
2
|
+
require 'digest/md5'
|
|
3
|
+
|
|
4
|
+
def ssh_command(command)
|
|
5
|
+
"ssh 2>&1 -o BatchMode=yes -o StrictHostKeyChecking=no -t #{@gear.uuid}@#{@app.name}-#{@account.domain}.dev.rhcloud.com " + command
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
Then /^I can run "([^\"]*)" with exit code: (\d+)$/ do |cmd, code|
|
|
9
|
+
command = ssh_command("rhcsh #{cmd}")
|
|
10
|
+
|
|
11
|
+
$logger.debug "Running #{command}"
|
|
12
|
+
|
|
13
|
+
output = `#{command}`
|
|
14
|
+
|
|
15
|
+
$logger.debug "Output: #{output}"
|
|
16
|
+
|
|
17
|
+
assert_equal code.to_i, $?.exitstatus
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
When /^I tail the logs via ssh$/ do
|
|
21
|
+
ssh_cmd = ssh_command("tail -f */logs/\\*")
|
|
22
|
+
stdout, stdin, pid = PTY.spawn ssh_cmd
|
|
23
|
+
|
|
24
|
+
@ssh_cmd = {
|
|
25
|
+
:pid => pid,
|
|
26
|
+
:stdin => stdin,
|
|
27
|
+
:stdout => stdout,
|
|
28
|
+
}
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
When /^I stop tailing the logs$/ do
|
|
32
|
+
begin
|
|
33
|
+
Process.kill('KILL', @ssh_cmd[:pid])
|
|
34
|
+
exit_code = -1
|
|
35
|
+
|
|
36
|
+
# Don't let a command run more than 1 minute
|
|
37
|
+
Timeout::timeout(60) do
|
|
38
|
+
ignored, status = Process::waitpid2 @ssh_cmd[:pid]
|
|
39
|
+
exit_code = status.exitstatus
|
|
40
|
+
end
|
|
41
|
+
rescue PTY::ChildExited
|
|
42
|
+
# Completed as expected
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
Then /^I can obtain disk quota information via SSH$/ do
|
|
47
|
+
cmd = ssh_command('/usr/bin/quota')
|
|
48
|
+
|
|
49
|
+
$logger.debug "Running: #{cmd}"
|
|
50
|
+
|
|
51
|
+
out = `#{cmd}`
|
|
52
|
+
|
|
53
|
+
$logger.debug "Output: #{out}"
|
|
54
|
+
|
|
55
|
+
if out.index("Disk quotas for user ").nil?
|
|
56
|
+
raise "Could not obtain disk quota information"
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
require 'fileutils'
|
|
2
|
+
require 'logger'
|
|
3
|
+
require 'etc'
|
|
4
|
+
|
|
5
|
+
#
|
|
6
|
+
# Define global variables
|
|
7
|
+
#
|
|
8
|
+
$temp = "/tmp/rhc"
|
|
9
|
+
|
|
10
|
+
$client_config = "/etc/openshift/express.conf"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# Use the domain from the rails application configuration
|
|
14
|
+
$domain = "example.com"
|
|
15
|
+
|
|
16
|
+
# Set the dns helper module
|
|
17
|
+
$dns_helper_module = File.dirname(__FILE__) + "/dns_helper.rb"
|
|
18
|
+
$bind_keyvalue=""
|
|
19
|
+
|
|
20
|
+
# oddjob service name and selinux context (specify nil if no alternate context is being used)
|
|
21
|
+
$gear_update_plugin_service = "oddjobd"
|
|
22
|
+
$selinux_user = "unconfined_u"
|
|
23
|
+
$selinux_role = "system_r"
|
|
24
|
+
$selinux_type = "openshift_initrc_t"
|
|
25
|
+
|
|
26
|
+
# User registration flag and script
|
|
27
|
+
$registration_required = true
|
|
28
|
+
if File.exists?("/etc/openshift/plugins.d/openshift-origin-auth-mongo.conf")
|
|
29
|
+
$user_register_script_format = "/usr/bin/oo-register-user -l admin -p admin --username %s --userpass %s"
|
|
30
|
+
elsif File.exists?("/etc/openshift/plugins.d/openshift-origin-auth-remote-user.conf")
|
|
31
|
+
$user_register_script_format = "/usr/bin/htpasswd -b /etc/openshift/htpasswd %s %s"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Alternatie domain suffix for use in alias commands
|
|
35
|
+
$alias_domain = "foobar.com"
|
|
36
|
+
|
|
37
|
+
# Submodule repo directory for testing submodule addition test case
|
|
38
|
+
$submodule_repo_dir = "#{Etc.getpwuid.dir}/submodule_test_repo"
|
|
39
|
+
|
|
40
|
+
#
|
|
41
|
+
# Old RHC Client scripts
|
|
42
|
+
#
|
|
43
|
+
$create_app_script = "/usr/bin/rhc-create-app"
|
|
44
|
+
$create_domain_script = "/usr/bin/rhc-create-domain"
|
|
45
|
+
$ctl_app_script = "/usr/bin/rhc-ctl-app"
|
|
46
|
+
$user_info_script = "/usr/bin/rhc-domain-info"
|
|
47
|
+
$snapshot_script = "/usr/bin/rhc-snapshot"
|
|
48
|
+
|
|
49
|
+
#
|
|
50
|
+
# New RHC Client scripts
|
|
51
|
+
#
|
|
52
|
+
$rhc_script = '/usr/bin/rhc'
|
|
53
|
+
|
|
54
|
+
# RSA Key constants
|
|
55
|
+
$test_pub_key = File.expand_path("~/.ssh/id_rsa.pub")
|
|
56
|
+
$test_priv_key = File.expand_path("~/.ssh/id_rsa")
|
|
57
|
+
|
|
58
|
+
module SetupHelper
|
|
59
|
+
def self.setup
|
|
60
|
+
# Create the temporary space
|
|
61
|
+
FileUtils.mkdir_p $temp
|
|
62
|
+
|
|
63
|
+
# Remove all temporary data
|
|
64
|
+
#FileUtils.rm_rf Dir.glob(File.join($temp, "*"))
|
|
65
|
+
|
|
66
|
+
# Setup the logger
|
|
67
|
+
$logger = Logger.new(File.join($temp, "cucumber.log"))
|
|
68
|
+
$logger.level = Logger::DEBUG
|
|
69
|
+
$logger.formatter = proc do |severity, datetime, progname, msg|
|
|
70
|
+
"#{$$} #{severity} #{datetime}: #{msg}\n"
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Setup performance monitor logger
|
|
74
|
+
$perfmon_logger = Logger.new(File.join($temp, "perfmon.log"))
|
|
75
|
+
$perfmon_logger.level = Logger::INFO
|
|
76
|
+
$perfmon_logger.formatter = proc do |severity, datetime, progname, msg|
|
|
77
|
+
"#{$$} #{datetime}: #{msg}\n"
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# If the default ssh key is not present, create one
|
|
81
|
+
`ssh-keygen -q -f #{$test_priv_key} -P ''` if !File.exists?($test_priv_key)
|
|
82
|
+
FileUtils.chmod 0600, $test_priv_key
|
|
83
|
+
|
|
84
|
+
# create a submodule repo for the tests
|
|
85
|
+
if !File.exists?($submodule_repo_dir)
|
|
86
|
+
`git init #{$submodule_repo_dir}`
|
|
87
|
+
Dir.chdir($submodule_repo_dir) do
|
|
88
|
+
`echo Submodule > index`
|
|
89
|
+
`git add index`
|
|
90
|
+
`git commit -m 'test'`
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# set the bind keyvalue from the installed plugin config
|
|
95
|
+
if File.exists?("/etc/openshift/plugins.d/openshift-origin-dns-bind.conf")
|
|
96
|
+
$bind_keyvalue = `cat /var/named/example.com.key | grep -i secret | gawk -F ' ' '{ print $2 }'`
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Create the ~/.ssh directory and ~/.ssh/config file and set the correct permissions
|
|
100
|
+
`mkdir -m 700 -p ~/.ssh`
|
|
101
|
+
`touch ~/.ssh/config`
|
|
102
|
+
`chmod 600 ~/.ssh/config`
|
|
103
|
+
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
World(SetupHelper)
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
require 'active_support'
|
|
2
|
+
require $dns_helper_module
|
|
3
|
+
|
|
4
|
+
module AppHelper
|
|
5
|
+
class TestApp
|
|
6
|
+
include ActiveSupport::JSON
|
|
7
|
+
include DnsHelper
|
|
8
|
+
|
|
9
|
+
# The regex to parse the ssh output from the create app results
|
|
10
|
+
SSH_OUTPUT_PATTERN = %r|ssh://([^@]+)@([^/]+)|
|
|
11
|
+
|
|
12
|
+
# Default password
|
|
13
|
+
DEFPASSWD = "xyz123"
|
|
14
|
+
|
|
15
|
+
# attributes to represent the general information of the application
|
|
16
|
+
attr_accessor :name, :namespace, :login, :password, :type, :hostname, :repo, :file, :embed, :snapshot, :uid, :git_url, :owner
|
|
17
|
+
|
|
18
|
+
# attributes to represent the state of the rhc_create_* commands
|
|
19
|
+
attr_accessor :create_domain_code, :create_app_code
|
|
20
|
+
|
|
21
|
+
# attributes that contain statistics based on calls to connect
|
|
22
|
+
attr_accessor :response_code, :response_time
|
|
23
|
+
|
|
24
|
+
# mysql connection information
|
|
25
|
+
attr_accessor :mysql_hostname, :mysql_user, :mysql_password, :mysql_database
|
|
26
|
+
|
|
27
|
+
# jenkins connection information
|
|
28
|
+
attr_accessor :jenkins_url, :jenkins_job_url, :jenkins_user, :jenkins_password, :jenkins_build
|
|
29
|
+
|
|
30
|
+
# Create the data structure for a test application
|
|
31
|
+
def initialize(namespace, login, type, name, password, owner)
|
|
32
|
+
@name, @namespace, @login, @type, @password, @owner = name, namespace, login, type, password, owner
|
|
33
|
+
@hostname = "#{name}-#{namespace}.#{$domain}"
|
|
34
|
+
@repo = "#{$temp}/#{namespace}_#{name}_repo"
|
|
35
|
+
@file = "#{$temp}/#{namespace}.json"
|
|
36
|
+
@embed = []
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def self.create_unique(type, name="test")
|
|
40
|
+
loop do
|
|
41
|
+
# Generate a random username
|
|
42
|
+
chars = ("1".."9").to_a
|
|
43
|
+
namespace = "ci" + Array.new(8, '').collect{chars[rand(chars.size)]}.join
|
|
44
|
+
login = "cucumber-test_#{namespace}@example.com"
|
|
45
|
+
app = TestApp.new(namespace, login, type, name, DEFPASSWD, Process.pid)
|
|
46
|
+
unless app.reserved?
|
|
47
|
+
app.persist
|
|
48
|
+
return app
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def self.find_on_fs
|
|
54
|
+
Dir.glob("#{$temp}/*.json").collect {|f| TestApp.from_file(f)}.select { |app| ( ( app.owner == Process.pid ) or app.owner.nil? ) }
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def self.from_file(filename)
|
|
58
|
+
TestApp.from_json(ActiveSupport::JSON.decode(File.open(filename, "r") {|f| f.readlines}[0]))
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def self.from_json(json)
|
|
62
|
+
app = TestApp.new(json['namespace'], json['login'], json['type'], json['name'], json['password'], json['owner'])
|
|
63
|
+
app.embed = json['embed']
|
|
64
|
+
app.mysql_user = json['mysql_user']
|
|
65
|
+
app.mysql_password = json['mysql_password']
|
|
66
|
+
app.mysql_hostname = json['mysql_hostname']
|
|
67
|
+
app.uid = json['uid']
|
|
68
|
+
return app
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def update_jenkins_info
|
|
72
|
+
@jenkins_user = `source /var/lib/openshift/#{@uid}/.env/JENKINS_USERNAME;echo $JENKINS_USERNAME`.chomp!
|
|
73
|
+
@jenkins_password = `source /var/lib/openshift/#{@uid}/.env/JENKINS_PASSWORD;echo $JENKINS_PASSWORD`.chomp!
|
|
74
|
+
@jenkins_url = `source /var/lib/openshift/#{@uid}/.env/JENKINS_URL;echo $JENKINS_URL`.chomp!
|
|
75
|
+
|
|
76
|
+
@jenkins_job_url = "#{@jenkins_url}job/#{@name}-build/"
|
|
77
|
+
@jenkins_build = "curl -ksS -X GET #{@jenkins_job_url}api/json --user '#{@jenkins_user}:#{@jenkins_password}'"
|
|
78
|
+
|
|
79
|
+
$logger.debug %Q{
|
|
80
|
+
jenkins_url = #{@jenkins_url}
|
|
81
|
+
jenkins_user = #{@jenkins_user}
|
|
82
|
+
jenkins_password = #{@jenkins_password}
|
|
83
|
+
jenkins_build = #{@jenkins_build}
|
|
84
|
+
}
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def update_uid(std_output)
|
|
88
|
+
begin
|
|
89
|
+
match = std_output.lines.map {|line| line.match(SSH_OUTPUT_PATTERN)}.compact[0]
|
|
90
|
+
@uid = match[1]
|
|
91
|
+
rescue => e
|
|
92
|
+
$logger.error "update_uid failed: #{e.message}\n#{std_output}"
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def update_git_url(std_output)
|
|
97
|
+
match = std_output.map {|line| line.match(%r|git url: (.*)|)}
|
|
98
|
+
@git_url = match.compact.first[1] if not match.nil?
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def get_log(prefix)
|
|
102
|
+
"#{$temp}/#{prefix}_#{@name}-#{@namespace}.log"
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def persist
|
|
106
|
+
# Because the system I/O is high during testing, this doesn't always
|
|
107
|
+
# succeed right away.
|
|
108
|
+
5.times do
|
|
109
|
+
begin
|
|
110
|
+
File.open(@file, "w") {|f| f.puts self.to_json}
|
|
111
|
+
break
|
|
112
|
+
rescue Errno::ENOENT
|
|
113
|
+
$logger.debug("Retrying file write for #{@file}")
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def reserved?
|
|
119
|
+
return (!namespace_available?(@namespace) or File.exists?(@file))
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def has_domain?
|
|
123
|
+
return create_domain_code == 0
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def get_index_file
|
|
127
|
+
case @type
|
|
128
|
+
when "php-5.3" then "php/index.php"
|
|
129
|
+
when "ruby-1.8" then "config.ru"
|
|
130
|
+
when "ruby-1.9" then "config.ru"
|
|
131
|
+
when "python-2.6" then "wsgi/application"
|
|
132
|
+
when "perl-5.10" then "perl/index.pl"
|
|
133
|
+
when "jbossas-7" then "src/main/webapp/index.html"
|
|
134
|
+
when "jbosseap-6.0" then "src/main/webapp/index.html"
|
|
135
|
+
when "jbossews-1.0" then "src/main/webapp/index.html"
|
|
136
|
+
when "nodejs-0.6" then "index.html"
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def get_mysql_file
|
|
141
|
+
case @type
|
|
142
|
+
when "php-5.3" then File.expand_path("../misc/php/db_test.php", File.expand_path(File.dirname(__FILE__)))
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def get_stop_string
|
|
147
|
+
"stopped"
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def curl(url, timeout=30)
|
|
151
|
+
body = `curl --insecure -s --max-time #{timeout} #{url}`
|
|
152
|
+
exit_code = $?.exitstatus
|
|
153
|
+
|
|
154
|
+
return exit_code, body
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def curl_head_success?(url, host=nil, http_code=200)
|
|
158
|
+
response_code = curl_head(url, host)
|
|
159
|
+
is_http = url.start_with?('http://')
|
|
160
|
+
if (is_http && response_code.to_i == 301)
|
|
161
|
+
url = "https://#{url[7..-1]}"
|
|
162
|
+
response_code = curl_head(url, host)
|
|
163
|
+
end
|
|
164
|
+
return response_code.to_i == http_code
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def curl_head(url, host=nil)
|
|
168
|
+
auth = "--user #{@jenkins_user}:#{@jenkins_password}" if @jenkins_user
|
|
169
|
+
host = "-H 'Host: #{host}'" if host
|
|
170
|
+
`curl -w %{http_code} --output /dev/null --insecure -s --head --max-time 30 #{auth} #{host} #{url}`
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def is_inaccessible?(max_retries=60)
|
|
174
|
+
max_retries.times do |i|
|
|
175
|
+
if !curl_head_success?("http://#{hostname}")
|
|
176
|
+
return true
|
|
177
|
+
else
|
|
178
|
+
$logger.info("Connection still accessible / retry #{i} of #{max_tries} / #{hostname}")
|
|
179
|
+
sleep 1
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
return false
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
# Host is for the host header
|
|
186
|
+
def is_accessible?(use_https=false, max_retries=120, host=nil)
|
|
187
|
+
prefix = use_https ? "https://" : "http://"
|
|
188
|
+
url = prefix + hostname
|
|
189
|
+
|
|
190
|
+
max_retries.times do |i|
|
|
191
|
+
if curl_head_success?(url, host)
|
|
192
|
+
return true
|
|
193
|
+
else
|
|
194
|
+
$logger.info("Connection still inaccessible / retry #{i} / #{url}")
|
|
195
|
+
sleep 1
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
return false
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def is_temporarily_unavailable?(use_https=false, host=nil)
|
|
203
|
+
prefix = use_https ? "https://" : "http://"
|
|
204
|
+
url = prefix + hostname
|
|
205
|
+
|
|
206
|
+
if curl_head_success?(url, host, 503)
|
|
207
|
+
return true
|
|
208
|
+
else
|
|
209
|
+
return false
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def last_access_file_present?
|
|
214
|
+
File.exists? "/var/lib/openshift/.last_access/#{uid}"
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def connect(use_https=false, max_retries=30)
|
|
218
|
+
prefix = use_https ? "https://" : "http://"
|
|
219
|
+
url = prefix + hostname
|
|
220
|
+
|
|
221
|
+
$logger.info("Connecting to #{url}")
|
|
222
|
+
beginning_time = Time.now
|
|
223
|
+
|
|
224
|
+
max_retries.times do |i|
|
|
225
|
+
code, body = curl(url, 1)
|
|
226
|
+
|
|
227
|
+
if code == 0
|
|
228
|
+
@response_code = code.to_i
|
|
229
|
+
@response_time = Time.now - beginning_time
|
|
230
|
+
$logger.info("Connection result = #{code} / #{url}")
|
|
231
|
+
$logger.info("Connection response time = #{@response_time} / #{url}")
|
|
232
|
+
return body
|
|
233
|
+
else
|
|
234
|
+
$logger.info("Connection failed / retry #{i} of #{max_retries} / #{url}")
|
|
235
|
+
sleep 1
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
return nil
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
end
|
|
243
|
+
World(AppHelper)
|