Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
8a21f226
Commit
8a21f226
authored
Apr 17, 2014
by
James Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ec2_eip integration tests.
parent
a37a8424
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
4 deletions
+51
-4
test/integration/Makefile
+1
-1
test/integration/cleanup_ec2.py
+49
-3
test/integration/roles/test_ec2_eip/defaults/main.yml
+1
-0
test/integration/roles/test_ec2_eip/tasks/main.yml
+0
-0
No files found.
test/integration/Makefile
View file @
8a21f226
...
...
@@ -48,7 +48,7 @@ $(CREDENTIALS_FILE):
@
exit
1
amazon
:
$(CREDENTIALS_FILE)
ansible-playbook amazon.yml
-i
$(INVENTORY)
-e
@
$(VARS_FILE)
$(CREDENTIALS_ARG)
-e
"resource_prefix=
$(CLOUD_RESOURCE_PREFIX)
"
-v
$(TEST_FLAGS)
;
\
BOTO_CONFIG
=
/dev/null
ansible-playbook amazon.yml
-i
$(INVENTORY)
-e
@
$(VARS_FILE)
$(CREDENTIALS_ARG)
-e
"resource_prefix=
$(CLOUD_RESOURCE_PREFIX)
"
-v
$(TEST_FLAGS)
;
\
RC
=
$$
?
;
\
CLOUD_RESOURCE_PREFIX
=
"
$(CLOUD_RESOURCE_PREFIX)
"
make amazon_cleanup
;
\
exit
$$
RC
;
...
...
test/integration/cleanup_ec2.py
View file @
8a21f226
...
...
@@ -10,6 +10,7 @@ import sys
import
boto
import
optparse
import
yaml
import
os.path
def
delete_aws_resources
(
get_func
,
attr
,
opts
):
for
item
in
get_func
():
...
...
@@ -17,13 +18,36 @@ def delete_aws_resources(get_func, attr, opts):
if
re
.
search
(
opts
.
match_re
,
val
):
prompt_and_delete
(
item
,
"Delete matching
%
s? [y/n]: "
%
(
item
,),
opts
.
assumeyes
)
def
delete_aws_eips
(
get_func
,
attr
,
opts
):
# the file might not be there if the integration test wasn't run
try
:
eip_log
=
open
(
opts
.
eip_log
,
'r'
)
.
read
()
.
splitlines
()
except
IOError
:
print
opts
.
eip_log
,
'not found.'
return
for
item
in
get_func
():
val
=
getattr
(
item
,
attr
)
if
val
in
eip_log
:
prompt_and_delete
(
item
,
"Delete matching
%
s? [y/n]: "
%
(
item
,),
opts
.
assumeyes
)
def
delete_aws_instances
(
reservation
,
opts
):
for
list
in
reservation
:
for
item
in
list
.
instances
:
prompt_and_delete
(
item
,
"Delete matching
%
s? [y/n]: "
%
(
item
,),
opts
.
assumeyes
)
def
prompt_and_delete
(
item
,
prompt
,
assumeyes
):
if
not
assumeyes
:
assumeyes
=
raw_input
(
prompt
)
.
lower
()
==
'y'
assert
hasattr
(
item
,
'delete'
)
,
"Class <
%
s> has no dele
te attribute"
%
item
.
__class__
assert
hasattr
(
item
,
'delete'
)
or
hasattr
(
item
,
'terminate'
)
,
"Class <
%
s> has no delete or termina
te attribute"
%
item
.
__class__
if
assumeyes
:
item
.
delete
()
print
(
"Deleted
%
s"
%
item
)
if
hasattr
(
item
,
'delete'
):
item
.
delete
()
print
(
"Deleted
%
s"
%
item
)
if
hasattr
(
item
,
'terminate'
):
item
.
terminate
()
print
(
"Terminated
%
s"
%
item
)
def
parse_args
():
# Load details from credentials.yml
...
...
@@ -47,6 +71,14 @@ def parse_args():
action
=
"store"
,
dest
=
"ec2_secret_key"
,
default
=
default_aws_secret_key
,
help
=
"Amazon ec2 secret key. Can use EC2_SECRET_KEY environment variable, or a values from credentials.yml."
)
parser
.
add_option
(
"--eip-log"
,
action
=
"store"
,
dest
=
"eip_log"
,
default
=
None
,
help
=
"Path to log of EIPs created during test."
)
parser
.
add_option
(
"--integration-config"
,
action
=
"store"
,
dest
=
"int_config"
,
default
=
"integration_config.yml"
,
help
=
"path to integration config"
)
parser
.
add_option
(
"--credentials"
,
"-c"
,
action
=
"store"
,
dest
=
"credential_file"
,
default
=
"credentials.yml"
,
...
...
@@ -65,12 +97,18 @@ def parse_args():
if
getattr
(
opts
,
required
)
is
None
:
parser
.
error
(
"Missing required parameter: --
%
s"
%
required
)
return
(
opts
,
args
)
if
__name__
==
'__main__'
:
(
opts
,
args
)
=
parse_args
()
int_config
=
yaml
.
load
(
open
(
opts
.
int_config
)
.
read
())
if
not
opts
.
eip_log
:
output_dir
=
os
.
path
.
expanduser
(
int_config
[
"output_dir"
])
opts
.
eip_log
=
output_dir
+
'/'
+
opts
.
match_re
.
replace
(
'^'
,
''
)
+
'-eip_integration_tests.log'
# Connect to AWS
aws
=
boto
.
connect_ec2
(
aws_access_key_id
=
opts
.
ec2_access_key
,
aws_secret_access_key
=
opts
.
ec2_secret_key
)
...
...
@@ -81,5 +119,13 @@ if __name__ == '__main__':
# Delete matching groups
delete_aws_resources
(
aws
.
get_all_security_groups
,
'name'
,
opts
)
# Delete recorded EIPs
delete_aws_eips
(
aws
.
get_all_addresses
,
'public_ip'
,
opts
)
# Delete temporary instances
filters
=
{
"tag:Name"
:
opts
.
match_re
.
replace
(
'^'
,
''
),
"instance-state-name"
:
[
'running'
,
'pending'
,
'stopped'
]}
delete_aws_instances
(
aws
.
get_all_instances
(
filters
=
filters
),
opts
)
except
KeyboardInterrupt
,
e
:
print
"
\n
Exiting on user command."
test/integration/roles/test_ec2_eip/defaults/main.yml
View file @
8a21f226
---
# defaults file for test_ec2_eip
tag_prefix
:
'
{{resource_prefix}}'
test/integration/roles/test_ec2_eip/tasks/main.yml
View file @
8a21f226
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment