add customizable tempdir and remove extra code
This commit is contained in:
@@ -22,6 +22,7 @@ import httplib
|
||||
import os
|
||||
import paramiko
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
import unittest
|
||||
from boto.ec2.regioninfo import RegionInfo
|
||||
@@ -147,19 +148,20 @@ class SmokeTestCase(unittest.TestCase):
|
||||
except:
|
||||
pass
|
||||
|
||||
def bundle_image(self, image, kernel=False):
|
||||
cmd = 'euca-bundle-image -i %s' % image
|
||||
def bundle_image(self, image, tempdir='/tmp', kernel=False):
|
||||
tempdir = tempfile.mkdtemp()
|
||||
cmd = 'euca-bundle-image -i %s -d %s' % (image, tempdir)
|
||||
if kernel:
|
||||
cmd += ' --kernel true'
|
||||
status, output = commands.getstatusoutput(cmd)
|
||||
if status != 0:
|
||||
print '%s -> \n %s' % (cmd, output)
|
||||
raise Exception(output)
|
||||
return True
|
||||
return tempdir
|
||||
|
||||
def upload_image(self, bucket_name, image):
|
||||
def upload_image(self, bucket_name, image, tempdir='/tmp'):
|
||||
cmd = 'euca-upload-bundle -b '
|
||||
cmd += '%s -m /tmp/%s.manifest.xml' % (bucket_name, image)
|
||||
cmd += '%s -m %s/%s.manifest.xml' % (bucket_name, tempdir, image)
|
||||
status, output = commands.getstatusoutput(cmd)
|
||||
if status != 0:
|
||||
print '%s -> \n %s' % (cmd, output)
|
||||
@@ -183,29 +185,3 @@ class UserSmokeTestCase(SmokeTestCase):
|
||||
global TEST_DATA
|
||||
self.conn = self.connection_for_env()
|
||||
self.data = TEST_DATA
|
||||
|
||||
|
||||
def run_tests(suites):
|
||||
argv = FLAGS(sys.argv)
|
||||
if FLAGS.use_ipv6:
|
||||
global boto_v6
|
||||
boto_v6 = __import__('boto_v6')
|
||||
|
||||
if not os.getenv('EC2_ACCESS_KEY'):
|
||||
print >> sys.stderr, 'Missing EC2 environment variables. Please ' \
|
||||
'source the appropriate novarc file before ' \
|
||||
'running this test.'
|
||||
return 1
|
||||
|
||||
if FLAGS.suite:
|
||||
try:
|
||||
suite = suites[FLAGS.suite]
|
||||
except KeyError:
|
||||
print >> sys.stderr, 'Available test suites:', \
|
||||
', '.join(suites.keys())
|
||||
return 1
|
||||
|
||||
unittest.TextTestRunner(verbosity=2).run(suite)
|
||||
else:
|
||||
for suite in suites.itervalues():
|
||||
unittest.TextTestRunner(verbosity=2).run(suite)
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import commands
|
||||
import os
|
||||
import random
|
||||
import sys
|
||||
import time
|
||||
import unittest
|
||||
import tempfile
|
||||
import shutil
|
||||
|
||||
# If ../nova/__init__.py exists, add ../ to Python search path, so that
|
||||
# it will override what happens to be installed in /usr/(local/)lib/python...
|
||||
@@ -48,10 +48,18 @@ TEST_KEY = '%s_key' % TEST_PREFIX
|
||||
TEST_GROUP = '%s_group' % TEST_PREFIX
|
||||
class ImageTests(base.UserSmokeTestCase):
|
||||
def test_001_can_bundle_image(self):
|
||||
self.assertTrue(self.bundle_image(FLAGS.bundle_image))
|
||||
self.data['tempdir'] = tempfile.mkdtemp()
|
||||
self.assertTrue(self.bundle_image(FLAGS.bundle_image,
|
||||
self.data['tempdir']))
|
||||
|
||||
def test_002_can_upload_image(self):
|
||||
self.assertTrue(self.upload_image(TEST_BUCKET, FLAGS.bundle_image))
|
||||
try:
|
||||
self.assertTrue(self.upload_image(TEST_BUCKET,
|
||||
FLAGS.bundle_image,
|
||||
self.data['tempdir']))
|
||||
finally:
|
||||
if os.path.exists(self.data['tempdir']):
|
||||
shutil.rmtree(self.data['tempdir'])
|
||||
|
||||
def test_003_can_register_image(self):
|
||||
image_id = self.conn.register_image('%s/%s.manifest.xml' %
|
||||
|
||||
Reference in New Issue
Block a user