forj 1.0.1 → 1.0.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.
- checksums.yaml +4 -4
- data/.gitignore +7 -0
- data/.gitreview +4 -0
- data/Gemfile +21 -19
- data/Gemfile.lock +71 -0
- data/bin/forj +126 -83
- data/forj.gemspec +64 -0
- data/{lib → forj}/defaults.yaml +23 -1
- data/lib/appinit.rb +5 -5
- data/lib/build_tmpl/build-env.py +293 -0
- data/lib/cloud_test.rb +121 -0
- data/lib/forj-settings.rb +52 -39
- data/lib/forj/ForjCli.rb +11 -10
- data/lib/forj/ForjCore.rb +8 -6
- data/lib/forj/process/ForjProcess.rb +345 -82
- data/lib/ssh.rb +81 -20
- metadata +110 -80
- data/lib/compute.rb +0 -36
- data/lib/connection.rb +0 -144
- data/lib/down.rb +0 -60
- data/lib/forj-account.rb +0 -294
- data/lib/forj-config.rb +0 -522
- data/lib/helpers.rb +0 -56
- data/lib/lib-forj/lib/core/core.rb +0 -1740
- data/lib/lib-forj/lib/core/definition.rb +0 -441
- data/lib/lib-forj/lib/core/definition_internal.rb +0 -306
- data/lib/lib-forj/lib/core_process/CloudProcess.rb +0 -334
- data/lib/lib-forj/lib/core_process/global_process.rb +0 -406
- data/lib/lib-forj/lib/core_process/network_process.rb +0 -603
- data/lib/lib-forj/lib/lib-forj.rb +0 -37
- data/lib/lib-forj/lib/providers/hpcloud/Hpcloud.rb +0 -419
- data/lib/lib-forj/lib/providers/hpcloud/compute.rb +0 -108
- data/lib/lib-forj/lib/providers/hpcloud/network.rb +0 -117
- data/lib/lib-forj/lib/providers/hpcloud/security_groups.rb +0 -67
- data/lib/lib-forj/lib/providers/templates/compute.rb +0 -42
- data/lib/lib-forj/lib/providers/templates/core.rb +0 -61
- data/lib/lib-forj/lib/providers/templates/network.rb +0 -33
- data/lib/log.rb +0 -162
- data/lib/network.rb +0 -365
- data/lib/repositories.rb +0 -222
- data/lib/security.rb +0 -207
- data/lib/ssh.sh +0 -185
- data/spec/connection_spec.rb +0 -52
- data/spec/forj-config_spec.rb +0 -237
- data/spec/repositories_spec.rb +0 -50
data/lib/security.rb
DELETED
@@ -1,207 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
|
18
|
-
require 'rubygems'
|
19
|
-
require 'highline/import'
|
20
|
-
|
21
|
-
#
|
22
|
-
# SecurityGroup module
|
23
|
-
#
|
24
|
-
|
25
|
-
# TODO: Introduce most of HPCloud task in an hpcloud object.
|
26
|
-
module SecurityGroup
|
27
|
-
|
28
|
-
def get_or_create_security_group(oFC, name)
|
29
|
-
Logging.state("Searching for security group '%s'..." % [name])
|
30
|
-
security_group = get_security_group(oFC, name)
|
31
|
-
security_group = create_security_group(oFC, name) if not security_group
|
32
|
-
security_group
|
33
|
-
end
|
34
|
-
|
35
|
-
def create_security_group(oFC, name)
|
36
|
-
Logging.debug("creating security group '%s'" % [name])
|
37
|
-
begin
|
38
|
-
description = "Security group for blueprint '%s'" % [name]
|
39
|
-
oFC.oNetwork.security_groups.create(
|
40
|
-
:name => name,
|
41
|
-
:description => description
|
42
|
-
)
|
43
|
-
rescue => e
|
44
|
-
Logging.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def get_security_group(oFC, name)
|
49
|
-
Logging.state("Searching for security group '%s'" % [name])
|
50
|
-
oSSLError=SSLErrorMgt.new
|
51
|
-
begin
|
52
|
-
sgroups = oFC.oNetwork.security_groups.all({:name => name})
|
53
|
-
rescue => e
|
54
|
-
if not oSSLError.ErrorDetected(e.message,e.backtrace)
|
55
|
-
retry
|
56
|
-
end
|
57
|
-
Logging.fatal(1, "Unable to get list of security groups.", e)
|
58
|
-
end
|
59
|
-
case sgroups.length()
|
60
|
-
when 0
|
61
|
-
Logging.debug("No security group '%s' found" % [name] )
|
62
|
-
nil
|
63
|
-
when 1
|
64
|
-
Logging.debug("Found security group '%s'" % [sgroups[0].name])
|
65
|
-
sgroups[0]
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def delete_security_group(oFC, security_group)
|
70
|
-
oSSLError=SSLErrorMgt.new
|
71
|
-
begin
|
72
|
-
sec_group = get_security_group(oFC, security_group)
|
73
|
-
oFC.oNetwork.security_groups.get(sec_group.id).destroy
|
74
|
-
rescue => e
|
75
|
-
if not oSSLError.ErrorDetected(e.message,e.backtrace)
|
76
|
-
retry
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def create_security_group_rule(oFC, security_group_id, protocol, port_min, port_max)
|
82
|
-
Logging.debug("Creating ingress rule '%s:%s - %s to 0.0.0.0/0'" % [protocol, port_min, port_max])
|
83
|
-
oSSLError=SSLErrorMgt.new
|
84
|
-
begin
|
85
|
-
oFC.oNetwork.security_group_rules.create(
|
86
|
-
:security_group_id => security_group_id,
|
87
|
-
:direction => 'ingress',
|
88
|
-
:protocol => protocol,
|
89
|
-
:port_range_min => port_min,
|
90
|
-
:port_range_max => port_max,
|
91
|
-
:remote_ip_prefix => '0.0.0.0/0'
|
92
|
-
)
|
93
|
-
rescue StandardError => e
|
94
|
-
if not oSSLError.ErrorDetected(e.message,e.backtrace)
|
95
|
-
retry
|
96
|
-
end
|
97
|
-
msg = 'error creating the rule for port %s' % [port_min]
|
98
|
-
Logging.error msg
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def delete_security_group_rule(oFC, rule_id)
|
103
|
-
oSSLError=SSLErrorMgt.new
|
104
|
-
begin
|
105
|
-
oFC.oNetwork.security_group_rules.get(rule_id).destroy
|
106
|
-
rescue => e
|
107
|
-
if not oSSLError.ErrorDetected(e.message,e.backtrace)
|
108
|
-
retry
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def get_security_group_rule(oFC, security_group_id, port_min, port_max)
|
114
|
-
Logging.state("Searching for rule '%s - %s'" % [ port_min, port_max])
|
115
|
-
oSSLError = SSLErrorMgt.new
|
116
|
-
begin
|
117
|
-
sgroups = oFC.oNetwork.security_group_rules.all({:port_range_min => port_min, :port_range_max => port_max, :security_group_id => security_group_id})
|
118
|
-
case sgroups.length()
|
119
|
-
when 0
|
120
|
-
Logging.debug("No security rule '%s - %s' found" % [ port_min, port_max ] )
|
121
|
-
nil
|
122
|
-
else
|
123
|
-
Logging.debug("Found security rule '%s - %s'." % [ port_min, port_max ])
|
124
|
-
sgroups
|
125
|
-
end
|
126
|
-
rescue => e
|
127
|
-
if not oSSLError.ErrorDetected(e.message,e.backtrace)
|
128
|
-
retry
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
def get_or_create_rule(oFC, security_group_id, protocol, port_min, port_max)
|
134
|
-
rule = get_security_group_rule(oFC, security_group_id, port_min, port_max)
|
135
|
-
if not rule
|
136
|
-
rule = create_security_group_rule(oFC, security_group_id, protocol, port_min, port_max)
|
137
|
-
end
|
138
|
-
rule
|
139
|
-
end
|
140
|
-
|
141
|
-
def keypair_detect(keypair_name, key_fullpath)
|
142
|
-
# Build key data information structure.
|
143
|
-
# Take care of priv with or without .pem and pubkey with pub.
|
144
|
-
|
145
|
-
key_basename = File.basename(key_fullpath)
|
146
|
-
key_path = File.expand_path(File.dirname(key_fullpath))
|
147
|
-
|
148
|
-
mObj = key_basename.match(/^(.*?)(\.pem|\.pub)?$/)
|
149
|
-
key_basename = mObj[1]
|
150
|
-
|
151
|
-
private_key_ext = nil
|
152
|
-
private_key_ext = "" if File.exists?(File.join(key_path, key_basename))
|
153
|
-
private_key_ext = '.pem' if File.exists?(File.join(key_path, key_basename + '.pem'))
|
154
|
-
if private_key_ext
|
155
|
-
private_key_exist = true
|
156
|
-
private_key_name = key_basename + private_key_ext
|
157
|
-
else
|
158
|
-
private_key_exist = false
|
159
|
-
private_key_name = key_basename
|
160
|
-
end
|
161
|
-
|
162
|
-
public_key_exist = File.exists?(File.join(key_path, key_basename + '.pub'))
|
163
|
-
public_key_name = key_basename + '.pub'
|
164
|
-
|
165
|
-
|
166
|
-
{:keypair_name => keypair_name,
|
167
|
-
:keypair_path => key_path, :key_basename => key_basename,
|
168
|
-
:private_key_name => private_key_name, :private_key_exist? => private_key_exist,
|
169
|
-
:public_key_name => public_key_name, :public_key_exist? => public_key_exist,
|
170
|
-
}
|
171
|
-
end
|
172
|
-
|
173
|
-
def hpc_import_key(oForjAccount)
|
174
|
-
|
175
|
-
keys = keypair_detect(oForjAccount.get('keypair_name'), oForjAccount.get('keypair_path'))
|
176
|
-
account = oForjAccount.getAccountData(:account, :name)
|
177
|
-
|
178
|
-
Logging.fatal(1, "'keypair_path' undefined. check your config.yaml file.") if not keys[:keypair_path]
|
179
|
-
Logging.fatal(1, "'keypair_name' undefined. check your config.yaml file.") if not keys[:keypair_name]
|
180
|
-
Logging.fatal(1, "keypair '%s' are missing. Please call 'forj setup %s' to create the missing key pair required." % [keys[:keypair_name], account]) if not keys[:public_key_exist?]
|
181
|
-
|
182
|
-
public_key_path = File.join(keys[:keypair_path], keys[:public_key_name])
|
183
|
-
private_key_path = File.join(keys[:keypair_path], keys[:private_key_name])
|
184
|
-
|
185
|
-
if not File.exists?(File.join($HPC_KEYPAIRS, keys[:keypair_name] + '.pub'))
|
186
|
-
Logging.info("Importing your forj public key '%s' to hpcloud." % keys[:public_key_name])
|
187
|
-
command = 'hpcloud keypairs:import %s %s -a %s' % [keys[:keypair_name], public_key_path , account]
|
188
|
-
Logging.debug("Executing command '%s'" % command)
|
189
|
-
Kernel.system(command)
|
190
|
-
else
|
191
|
-
Logging.info("Using '%s' as public key." % public_key_path)
|
192
|
-
end
|
193
|
-
|
194
|
-
if not File.exists?(File.join($HPC_KEYPAIRS, keys[:keypair_name] + '.pem'))
|
195
|
-
if keys[:private_key_exist?]
|
196
|
-
Logging.info("Importing your forj private key '%s' to hpcloud." % private_key_path)
|
197
|
-
command = 'hpcloud keypairs:private:add %s %s' % [keys[:keypair_name], private_key_path]
|
198
|
-
Logging.debug("Executing command '%s'" % command)
|
199
|
-
Kernel.system(command)
|
200
|
-
else
|
201
|
-
Logging.warning('Unable to find the private key. This will be required to access with ssh to Maestro and any blueprint boxes.')
|
202
|
-
end
|
203
|
-
else
|
204
|
-
Logging.info("Using '%s' as private key." % private_key_path)
|
205
|
-
end
|
206
|
-
end
|
207
|
-
end
|
data/lib/ssh.sh
DELETED
@@ -1,185 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
#vim: setlocal ft=sh:
|
3
|
-
RST="\e[0m"
|
4
|
-
RED="\e[31m"
|
5
|
-
BLU="\e[34m"
|
6
|
-
GRE="\e[92m"
|
7
|
-
|
8
|
-
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
9
|
-
#
|
10
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
11
|
-
# you may not use this file except in compliance with the License.
|
12
|
-
# You may obtain a copy of the License at
|
13
|
-
#
|
14
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
15
|
-
#
|
16
|
-
# Unless required by applicable law or agreed to in writing, software
|
17
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
18
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19
|
-
# See the License for the specific language governing permissions and
|
20
|
-
# limitations under the License.
|
21
|
-
|
22
|
-
NOW=$(date +%Y-%m-%d.%H%M%S)
|
23
|
-
logpath=~/.forj/
|
24
|
-
DB=~/.forj/hosts
|
25
|
-
#key_path=~/.ssh/
|
26
|
-
#key_path=~/.hpcloud/keypairs/
|
27
|
-
init_config=~/ssh_init
|
28
|
-
key="nova.pem"
|
29
|
-
|
30
|
-
if [ ! -f $DB ]; then
|
31
|
-
cat > $DB <<'EOF'
|
32
|
-
|
33
|
-
#Custom Servers - (Won't be deleted when updating list)
|
34
|
-
#<name.id> <public ip> <date> <key>
|
35
|
-
|
36
|
-
#### Below list are updated
|
37
|
-
|
38
|
-
EOF
|
39
|
-
fi
|
40
|
-
|
41
|
-
##No parameters sent
|
42
|
-
if (( $# < 1 )); then
|
43
|
-
echo -e "${RED}Error, no parameter was sent.$RST"
|
44
|
-
echo "Use this script as:"
|
45
|
-
echo " -rm <id> : Removes all nodes that match the id."
|
46
|
-
echo " -f <text>: Finds the text in the log files."
|
47
|
-
echo " -u : Updates the hosts list querying nova server."
|
48
|
-
echo " -l : Lists the current hosts."
|
49
|
-
echo " <IP> : Connects directly to the IP using default key"
|
50
|
-
echo "<id> <name>: Queries the hosts list looking for the id and name."
|
51
|
-
echo -e "\n ${GRE}OPTIONS${RST}"
|
52
|
-
echo " -i {par} : Applies initialization script to the server."
|
53
|
-
exit 1
|
54
|
-
fi
|
55
|
-
|
56
|
-
if [ $1 == '-i' ]; then
|
57
|
-
if [ ! -f $init_config ]; then
|
58
|
-
echo "${RED}Error, config file: $init_config does not exists."
|
59
|
-
exit 1
|
60
|
-
fi
|
61
|
-
shift
|
62
|
-
is_init='true'
|
63
|
-
fi
|
64
|
-
|
65
|
-
#Finds text in logs
|
66
|
-
if [ $1 == '-f' ]; then
|
67
|
-
grep --include=*.log -rnw $logpath -e "$2" --color=always
|
68
|
-
exit 0
|
69
|
-
fi
|
70
|
-
|
71
|
-
if [ $1 == '-rm' ] && [ "$2" != '' ]; then
|
72
|
-
echo "Removing $2..."
|
73
|
-
cat $DB | grep -iE "[a-z]+\.$2" --color=always
|
74
|
-
sed -i -E "/[a-z]+\.$2/d" $DB
|
75
|
-
exit 0
|
76
|
-
fi
|
77
|
-
|
78
|
-
##Just Lists the hosts db
|
79
|
-
if [ $1 == '-l' ]; then
|
80
|
-
echo "List of hosts:"
|
81
|
-
if [ "$2" != "" ]; then #kit
|
82
|
-
result=$(cat $DB | grep -iE "\.$2" --color=always)
|
83
|
-
else #All Maestros
|
84
|
-
result=$(cat $DB | grep -E "maestro\.")
|
85
|
-
fi
|
86
|
-
echo "$result"
|
87
|
-
exit 0
|
88
|
-
fi
|
89
|
-
|
90
|
-
##Just list the hosts db
|
91
|
-
if [ $1 == '-u' ]; then
|
92
|
-
linenum=$(cat $DB | grep -E -n "#### Below list are updated" | awk -F: '{print $1}')
|
93
|
-
old_serversnum=$(tail -n +$linenum $DB | grep -E " .*\..* " | wc -l)
|
94
|
-
|
95
|
-
sed -i -n '/\#\#\#\# Below list are updated/q;p' $DB
|
96
|
-
sed -i '/^$/d' $DB
|
97
|
-
echo -e "\n#### Below list are updated" >> $DB
|
98
|
-
|
99
|
-
hpcloud servers -a $2 | awk -F"\|" '{print $3","$6","$9","$7}' | awk -F, '{print $1$3$4$5}' >> $DB
|
100
|
-
echo -e "\033[1;32m$DB Updated\033[00m"
|
101
|
-
linenum=$(cat $DB | grep -E -n "#### Below list are updated" | awk -F: '{print $1}')
|
102
|
-
new_serversnum=$(tail -n +$linenum $DB | grep -E " .*\..* " | wc -l)
|
103
|
-
diff=$(echo "$new_serversnum - $old_serversnum" | bc)
|
104
|
-
echo "Old Servers: $old_serversnum, New Servers: $new_serversnum, Diff: $diff"
|
105
|
-
exit 0
|
106
|
-
fi
|
107
|
-
|
108
|
-
#parameter is IP
|
109
|
-
if [[ $1 =~ ([0-9]{1,3}\.){3}[0-9]{1,3} ]]; then
|
110
|
-
ip=$1
|
111
|
-
#Check if has URL and clean it if so
|
112
|
-
if [[ $ip =~ 'http' ]]; then
|
113
|
-
ip=$(echo "$ip" | grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}')
|
114
|
-
fi
|
115
|
-
#Check if IP exists in db and show info
|
116
|
-
host_name=$(cat $DB | grep $ip | awk '{print $1}')
|
117
|
-
if [[ "$host_name" != "" ]]; then
|
118
|
-
echo -e "Host: \033[33m$host_name${RST}"
|
119
|
-
fi
|
120
|
-
message="$ip"
|
121
|
-
#parameter is ID NODE
|
122
|
-
else
|
123
|
-
id=$1
|
124
|
-
node=$2
|
125
|
-
key=$3
|
126
|
-
|
127
|
-
if [ "$node" == "" ]; then
|
128
|
-
echo -e "${RED}Error, no server name sent.$RST"
|
129
|
-
exit 1
|
130
|
-
fi
|
131
|
-
|
132
|
-
#Alias handling
|
133
|
-
alias=$(cat ~/hosts | grep -iE '^alias:' | grep -iE ' '$node | awk '{print $2}')
|
134
|
-
if [ "$alias" != "" ] && [ "$alias" != "$node" ]; then
|
135
|
-
echo "Using alias $node, converting to $alias"
|
136
|
-
node=$alias
|
137
|
-
fi
|
138
|
-
|
139
|
-
ip=$(cat $DB | grep -iE "[a-ZA-Z]+\.$id" | grep -i $node | awk '{print $2}' | tr -d ' ')
|
140
|
-
if [ "$ip" == "" ]; then
|
141
|
-
echo -e "${RED}Error, the kit ${GRE}$node${RED} with id ${GRE}$id${RED} was not found.${RST}"
|
142
|
-
exit 1
|
143
|
-
fi
|
144
|
-
#key=$(cat $DB | grep -iEw "$ip" | awk '{print $4}' | tr -d ' ')
|
145
|
-
message="$node.$id"
|
146
|
-
extended="($ip)"
|
147
|
-
|
148
|
-
if [ "$ip" == "" ] || [ "$key" == "" ]; then
|
149
|
-
echo -e "${RED}Error, combination was not found, maybe you should update the db.$RST"
|
150
|
-
exit 1
|
151
|
-
fi
|
152
|
-
fi
|
153
|
-
|
154
|
-
if [ "$node" != "" ]; then
|
155
|
-
logname="$node.$id"
|
156
|
-
else
|
157
|
-
logname="$ip"
|
158
|
-
fi
|
159
|
-
#key="$key_path$key.pem"
|
160
|
-
|
161
|
-
echo -e "Connecting to $GRE$message$RST using $BLU$key$RST $extended"
|
162
|
-
|
163
|
-
if [[ ! -f $key ]]; then
|
164
|
-
echo -e "${RED}Key doesn't exists$RST"
|
165
|
-
exit 1
|
166
|
-
fi
|
167
|
-
|
168
|
-
logfile="${logpath}sshlog.$logname.$NOW.log"
|
169
|
-
|
170
|
-
echo -e "$RED══════════════════════════════════════════════════════════════════════════$RST"
|
171
|
-
#echo "ssh -o StrictHostKeyChecking=no -o ServerAliveInterval=180 -i $key ubuntu@$ip"
|
172
|
-
if [ "$is_init" == 'true' ]; then
|
173
|
-
username=$(id -u -n)
|
174
|
-
username=${username^^} #convert to upper
|
175
|
-
grep -q "$username" $init_config
|
176
|
-
if [ $? != 0 ]; then
|
177
|
-
echo "Writing username to $init_config file."
|
178
|
-
sed -i "s/^owner='.*'$/owner='$username'/g" $DB
|
179
|
-
fi
|
180
|
-
ssh -o StrictHostKeyChecking=no -o ServerAliveInterval=180 -i $key ubuntu@$ip < $init_config
|
181
|
-
echo -e "Reconnecting..."
|
182
|
-
fi
|
183
|
-
ssh -o StrictHostKeyChecking=no -o ServerAliveInterval=180 -i $key ubuntu@$ip | tee -a $logfile
|
184
|
-
echo -e "$RED══════════════════════════════════════════════════════════════════════════$RST"
|
185
|
-
echo -e "${GRE}Log file: ${RST}$logfile"
|
data/spec/connection_spec.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
|
18
|
-
require 'rubygems'
|
19
|
-
require 'bundler/setup'
|
20
|
-
require 'spec_helper'
|
21
|
-
|
22
|
-
require 'fog'
|
23
|
-
|
24
|
-
$APP_PATH = File.dirname(__FILE__)
|
25
|
-
$LIB_PATH = File.expand_path(File.join(File.dirname($APP_PATH),'lib'))
|
26
|
-
|
27
|
-
$LOAD_PATH << $LIB_PATH
|
28
|
-
|
29
|
-
require 'appinit.rb' # Load generic Application level function
|
30
|
-
|
31
|
-
# Initialize forj paths
|
32
|
-
AppInit::forj_initialize()
|
33
|
-
|
34
|
-
# Initialize global Log object
|
35
|
-
$FORJ_LOGGER=ForjLog.new('forj-rspec.log', Logger::FATAL)
|
36
|
-
|
37
|
-
require 'forj-config.rb' # Load class ForjConfig
|
38
|
-
require 'connection.rb' # Load class ForjConnection
|
39
|
-
require 'forj-account.rb'
|
40
|
-
|
41
|
-
|
42
|
-
describe 'Module: forj-connection' do
|
43
|
-
|
44
|
-
it 'should connect to hpcloud (smoke test)' do
|
45
|
-
|
46
|
-
Fog.mock!
|
47
|
-
conn = ForjConnection.new(ForjAccount.new(ForjConfig.new()))
|
48
|
-
expect(conn).to be
|
49
|
-
|
50
|
-
Fog::Mock.reset
|
51
|
-
end
|
52
|
-
end
|
data/spec/forj-config_spec.rb
DELETED
@@ -1,237 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
|
18
|
-
require 'rubygems'
|
19
|
-
require 'bundler/setup'
|
20
|
-
|
21
|
-
$APP_PATH = File.dirname(__FILE__)
|
22
|
-
$LIB_PATH = File.expand_path(File.join(File.dirname($APP_PATH),'lib'))
|
23
|
-
$FORJ_DATA_PATH= File.expand_path('~/.forj')
|
24
|
-
|
25
|
-
$LOAD_PATH << './lib'
|
26
|
-
|
27
|
-
require 'forj-config.rb' # Load class ForjConfig
|
28
|
-
require 'log.rb' # Load default loggers
|
29
|
-
require 'ansi'
|
30
|
-
|
31
|
-
include Logging
|
32
|
-
|
33
|
-
$FORJ_LOGGER=ForjLog.new('forj-rspec.log', Logger::FATAL)
|
34
|
-
|
35
|
-
|
36
|
-
describe "class: forj-config," do
|
37
|
-
context "when creating a new instance" do
|
38
|
-
|
39
|
-
it 'should be loaded' do
|
40
|
-
@test_config=ForjConfig.new()
|
41
|
-
expect(@test_config).to be
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
context "when starting, forj-config" do
|
47
|
-
before(:all) do
|
48
|
-
@config=ForjConfig.new()
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'should be able to create a key/value in local config' do
|
52
|
-
@config.LocalSet(:test1,'value')
|
53
|
-
expect(@config.LocalGet(:test1)).to eq('value')
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'should be able to remove the previously created key/value from local config' do
|
57
|
-
@config.LocalDel(:test1)
|
58
|
-
expect(@config.exist?(:test1)).to equal(false)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context "while updating local config file, forj-config" do
|
63
|
-
before(:all) do
|
64
|
-
@config=ForjConfig.new()
|
65
|
-
end
|
66
|
-
|
67
|
-
after(:all) do
|
68
|
-
@config.LocalDel(:test1)
|
69
|
-
@config.SaveConfig()
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'should save a key/value in local config' do
|
73
|
-
@config.LocalSet(:test1,'value')
|
74
|
-
expect(@config.SaveConfig()).to equal(true)
|
75
|
-
|
76
|
-
oConfig=ForjConfig.new()
|
77
|
-
expect(@config.LocalGet(:test1)).to eq('value')
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
81
|
-
|
82
|
-
context "With another config file - test1.yaml, forj-config" do
|
83
|
-
|
84
|
-
before(:all) do
|
85
|
-
if File.exists?('~/.forj/test.yaml')
|
86
|
-
File.delete(File.expand_path('~/.forj/test.yaml'))
|
87
|
-
end
|
88
|
-
File.open(File.expand_path('~/.forj/test1.yaml'), 'w+') { |file| file.write(":default:\n") }
|
89
|
-
@config=ForjConfig.new('test.yaml')
|
90
|
-
@config2=ForjConfig.new('test1.yaml')
|
91
|
-
end
|
92
|
-
|
93
|
-
after(:all) do
|
94
|
-
File.delete(File.expand_path('~/.forj/test1.yaml'))
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'won\'t create a new file If we request to load \'test.yaml\'' do
|
98
|
-
expect(File.exists?(File.expand_path('~/.forj/test.yaml'))).to equal(false)
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'will load the default config file if we request to load \'test.yaml\'' do
|
102
|
-
expect(File.basename(@config.sConfigName)).to eq('config.yaml')
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'will confirm \'test1.yaml\' config to be loaded.' do
|
106
|
-
expect(File.basename(@config2.sConfigName)).to eq('test1.yaml')
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'can save \'test2=value\'' do
|
110
|
-
@config2.LocalSet('test2','value')
|
111
|
-
expect(@config2.SaveConfig()).to equal(true)
|
112
|
-
config3=ForjConfig.new('test1.yaml')
|
113
|
-
expect(config3.LocalGet('test2')).to eq('value')
|
114
|
-
end
|
115
|
-
|
116
|
-
end
|
117
|
-
|
118
|
-
context "with get/set/exists?," do
|
119
|
-
before(:all) do
|
120
|
-
@config=ForjConfig.new()
|
121
|
-
@url = @config.get('maestro_url')
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'can set and get data,' do
|
125
|
-
expect(@config.set(nil, nil)).to equal(false)
|
126
|
-
expect(@config.set(:test, nil)).to equal(true)
|
127
|
-
expect(@config.get(:test)).to equal(nil)
|
128
|
-
|
129
|
-
expect(@config.set(:test, 'data')).to equal(true)
|
130
|
-
expect(@config.get(:test)).to eq('data')
|
131
|
-
end
|
132
|
-
|
133
|
-
context 'from defaults,' do
|
134
|
-
it 'can get application defaults' do
|
135
|
-
expect(@config.get(:maestro_url).class).to equal(String)
|
136
|
-
expect(@config.getAppDefault(:default, :maestro_url).class).to equal(String)
|
137
|
-
expect(@config.getAppDefault(:description, 'FORJ_HPC').class).to equal(String)
|
138
|
-
|
139
|
-
end
|
140
|
-
it 'can get Local defaults instead of application' do
|
141
|
-
expect(@config.LocalSet(:maestro_url,'local')).to equal(true)
|
142
|
-
expect(@config.LocalGet(:maestro_url)).to eq('local')
|
143
|
-
expect(@config.get(:maestro_url)).to eq('local')
|
144
|
-
end
|
145
|
-
|
146
|
-
it 'can get runtime defaults instead of Local/application' do
|
147
|
-
expect(@config.set(:maestro_url, 'runtime')).to equal(true)
|
148
|
-
expect(@config.get(:maestro_url)).to eq('runtime')
|
149
|
-
expect(@config.LocalGet(:maestro_url)).to eq('local')
|
150
|
-
end
|
151
|
-
|
152
|
-
it 'can get runtime defaults instead of application' do
|
153
|
-
expect(@config.LocalDel(:maestro_url)).to equal(true)
|
154
|
-
expect(@config.get(:maestro_url)).to eq('runtime')
|
155
|
-
expect(@config.LocalGet(:maestro_url)).to equal(nil)
|
156
|
-
end
|
157
|
-
|
158
|
-
it 'can get defaults if no key' do
|
159
|
-
expect(@config.set(:test1, nil)).to equal(true)
|
160
|
-
expect(@config.get(:test1, 'default')).to eq('default')
|
161
|
-
expect(@config.get(:test1, nil)).to equal(nil)
|
162
|
-
expect(@config.set(:maestro_url,nil)).to equal(true)
|
163
|
-
expect(@config.get(:maestro_url)).to eq(@url)
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
context 'with intermediates,' do
|
168
|
-
before(:all) do
|
169
|
-
@yYAML1={ :maestro_url => 'url1' }
|
170
|
-
@aArray1=[]
|
171
|
-
@aArray1[0]={ :maestro_url => 'url2' }
|
172
|
-
@aArray1[1]=@yYAML1
|
173
|
-
@aArray2=[]
|
174
|
-
@aArray2[0] = @aArray1[1]
|
175
|
-
@aArray2[1] = @aArray1[0]
|
176
|
-
@aArray3=[]
|
177
|
-
@aArray3[0] = { :hash_1 => { :maestro_url => 'url3' }}
|
178
|
-
@aArray3[1] = { :hash_2 => { :keypair_name => 'nova' }}
|
179
|
-
@aArray4=[]
|
180
|
-
@aArray4[0] = { :hash_1 => { :keypair_name => 'nova' }}
|
181
|
-
@aArray4[1] = { :hash_2 => { :maestro_url => 'url4' }}
|
182
|
-
end
|
183
|
-
|
184
|
-
# Obsolete.
|
185
|
-
#~ it 'can get data from one hash' do
|
186
|
-
#~ expect(@config.get(:maestro_url, @yYAML1)).to eq('url1')
|
187
|
-
#~ @config.set(:maestro_url, 'runtime')
|
188
|
-
#~ expect(@config.get(:maestro_url, @yYAML1)).to eq('runtime')
|
189
|
-
#~ end
|
190
|
-
#~
|
191
|
-
#~ it 'can get data from array of hash' do
|
192
|
-
#~ @config.set(:maestro_url, nil)
|
193
|
-
#~ expect(@config.get(:maestro_url, @aArray1)).to eq('url2')
|
194
|
-
#~ expect(@config.get(:maestro_url, @aArray2)).to eq('url1')
|
195
|
-
#~ end
|
196
|
-
#~ it 'can get data from array of hashes' do
|
197
|
-
#~ @config.set('maestro_url', nil)
|
198
|
-
#~ expect(@config.exist?(:maestro_url, @aArray3)).to eq('hash_1')
|
199
|
-
#~ expect(@config.exist?(:maestro_url, @aArray4)).to eq('hash_2')
|
200
|
-
#~ expect(@config.get(:maestro_url, @aArray3)).to eq('url3')
|
201
|
-
#~ expect(@config.get(:maestro_url, @aArray4)).to eq('url4')
|
202
|
-
#~ end
|
203
|
-
end
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
describe 'Recursive Hash functions,' do
|
208
|
-
context "With recursive Hash functions" do
|
209
|
-
it 'can create a 3 levels of hash' do
|
210
|
-
yYAML = rhSet(nil, 'level4', :level1, :level2, :level3)
|
211
|
-
expect(yYAML[:level1][:level2][:level3]).to eq('level4')
|
212
|
-
end
|
213
|
-
|
214
|
-
it 'can add a 3 levels of hash in an existing hash' do
|
215
|
-
yYAML = rhSet(nil, 'level4', :level1, :level2, :level3)
|
216
|
-
yYAML = rhSet(yYAML, 'level1.1', :level1_1)
|
217
|
-
expect(yYAML[:level1][:level2][:level3]).to eq('level4')
|
218
|
-
expect(yYAML[:level1_1]).to eq('level1.1')
|
219
|
-
end
|
220
|
-
|
221
|
-
it 'can get each levels of hash data' do
|
222
|
-
yYAML = rhSet(nil, 'level4', :level1, :level2, :level3)
|
223
|
-
expect(rhGet(yYAML, :level1).class).to equal(Hash)
|
224
|
-
expect(rhGet(yYAML, :level1, :level2).class).to equal(Hash)
|
225
|
-
expect(rhGet(yYAML, :level1, :level2, :level3).class).to equal(String)
|
226
|
-
end
|
227
|
-
|
228
|
-
it 'can check existence of each levels of hash data' do
|
229
|
-
yYAML = rhSet(nil, 'level4', :level1, :level2, :level3)
|
230
|
-
expect(rhExist?(yYAML, :level1)).to eq(1)
|
231
|
-
expect(rhExist?(yYAML, :level1, :level2)).to eq(2)
|
232
|
-
expect(rhExist?(yYAML, :level1, :level2, :level3)).to eq(3)
|
233
|
-
expect(rhExist?(yYAML, :level1_1, :level2, :level3)).to eq(0)
|
234
|
-
|
235
|
-
end
|
236
|
-
end
|
237
|
-
end
|