-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move CgcloudTestCase to lib.test so Toil can use it
- Loading branch information
1 parent
1c8db66
commit f032719
Showing
8 changed files
with
62 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
from bd2k.util.d64 import D64 | ||
|
||
aws_d64 = D64( '.-' ) # hopefully the dot is supported for all AWS resource names | ||
|
||
test_namespace_suffix_length = 11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import os | ||
import time | ||
from struct import pack | ||
from unittest import TestCase | ||
|
||
from boto.utils import get_instance_metadata | ||
|
||
from cgcloud.lib import aws_d64, test_namespace_suffix_length | ||
from cgcloud.lib.context import Context | ||
from cgcloud.lib.ec2 import running_on_ec2 | ||
|
||
|
||
class CgcloudTestCase( TestCase ): | ||
""" | ||
A base class for CGCloud test cases. When run with CGCLOUD_NAMESPACE unset, a new test | ||
namespace will be prepared during setup and cleaned up during teardown. Otherwise, | ||
the configured namespace will be used but not cleaned up. | ||
""" | ||
__namespace = None | ||
cleanup = True | ||
ctx = None | ||
|
||
@classmethod | ||
def setUpClass( cls ): | ||
super( CgcloudTestCase, cls ).tearDownClass( ) | ||
if running_on_ec2( ): | ||
os.environ.setdefault( 'CGCLOUD_ZONE', | ||
get_instance_metadata( )[ 'placement' ][ 'availability-zone' ] ) | ||
# Using the d64 of a binary string that starts with a 4-byte, big-endian time stamp | ||
# yields compact names whose lexicographical sorting is consistent with the historical | ||
# order. We add the process ID so we can run tests concurrently in child processes using | ||
# the pytest-xdist plugin. | ||
suffix = aws_d64.encode( pack( '>II', int( time.time( ) ), os.getpid( ) ) ) | ||
assert len( suffix ) == test_namespace_suffix_length | ||
cls.__namespace = '/test/%s/' % suffix | ||
os.environ.setdefault( 'CGCLOUD_NAMESPACE', cls.__namespace ) | ||
cls.ctx = Context( availability_zone=os.environ[ 'CGCLOUD_ZONE' ], | ||
namespace=os.environ[ 'CGCLOUD_NAMESPACE' ] ) | ||
|
||
@classmethod | ||
def tearDownClass( cls ): | ||
# Only cleanup if the context is using the default test namespace. If another namespace | ||
# is configured, we can't assume that all resources were created by the test and that | ||
# they can therefore be removed. | ||
if cls.cleanup and cls.ctx.namespace == cls.__namespace: | ||
cls.ctx.reset_namespace_security( ) | ||
super( CgcloudTestCase, cls ).setUpClass( ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters