Fix unittests breakage from merge 3507905

PEP8 the file along the way.
This commit is contained in:
Chmouel Boudjnah 2011-09-01 15:35:44 -05:00
parent 2b1b109aab
commit 7c8ae25a89
2 changed files with 28 additions and 24 deletions

View File

@ -16,6 +16,7 @@ class ShellTest(utils.TestCase):
'NOVA_USERNAME': 'username',
'NOVA_API_KEY': 'password',
'NOVA_PROJECT_ID': 'project_id',
'NOVA_URL': 'http://no.where',
}
_old_env, os.environ = os.environ, fake_env.copy()

View File

@ -20,6 +20,8 @@ class ShellTest(utils.TestCase):
'NOVA_API_KEY': 'password',
'NOVA_PROJECT_ID': 'project_id',
'NOVA_VERSION': '1.1',
'NOVA_PROJECT_ID': 'project_id',
'NOVA_URL': 'http://no.where',
}
self.shell = OpenStackComputeShell()
@ -38,53 +40,53 @@ class ShellTest(utils.TestCase):
return self.shell.cs.assert_called_anytime(method, url, body)
def test_boot(self):
self.run_command('boot --image 1 some-server')
self.run_command('boot --flavor 1 --image 1 some-server')
self.assert_called_anytime(
'POST', '/servers',
{'server': {
'flavorRef': 1,
'flavorRef': '1',
'name': 'some-server',
'imageRef': '1',
'min_count': 1,
'max_count': 1,
}}
}},
)
self.run_command('boot --image 1 --meta foo=bar'
self.run_command('boot --image 1 --flavor 1 --meta foo=bar'
' --meta spam=eggs some-server ')
self.assert_called_anytime(
'POST', '/servers',
{'server': {
'flavorRef': 1,
'flavorRef': '1',
'name': 'some-server',
'imageRef': '1',
'metadata': {'foo': 'bar', 'spam': 'eggs'},
'min_count': 1,
'max_count': 1,
}}
}},
)
def test_boot_files(self):
testfile = os.path.join(os.path.dirname(__file__), 'testfile.txt')
expected_file_data = open(testfile).read().encode('base64')
cmd = 'boot some-server --image 1 ' \
cmd = 'boot some-server --flavor 1 --image 1 ' \
'--file /tmp/foo=%s --file /tmp/bar=%s'
self.run_command(cmd % (testfile, testfile))
self.assert_called_anytime(
'POST', '/servers',
{'server': {
'flavorRef': 1,
'flavorRef': '1',
'name': 'some-server',
'imageRef': '1',
'min_count': 1,
'max_count': 1,
'personality': [
{'path': '/tmp/bar', 'contents': expected_file_data},
{'path': '/tmp/foo', 'contents': expected_file_data}
]}
}
{'path': '/tmp/foo', 'contents': expected_file_data},
]},
},
)
def test_boot_invalid_file(self):
@ -102,11 +104,11 @@ class ShellTest(utils.TestCase):
@mock.patch('os.path.exists', mock_exists)
@mock.patch('__builtin__.open', mock_open)
def test_shell_call():
self.run_command('boot some-server --image 1 --key')
self.run_command('boot some-server --flavor 1 --image 1 --key')
self.assert_called_anytime(
'POST', '/servers',
{'server': {
'flavorRef': 1,
'flavorRef': '1',
'name': 'some-server',
'imageRef': '1',
'min_count': 1,
@ -114,8 +116,8 @@ class ShellTest(utils.TestCase):
'personality': [{
'path': '/root/.ssh/authorized_keys2',
'contents': ('SSHKEY').encode('base64')},
]}
}
]},
},
)
test_shell_call()
@ -126,18 +128,19 @@ class ShellTest(utils.TestCase):
@mock.patch('os.path.exists', mock_exists)
def test_shell_call():
self.assertRaises(exceptions.CommandError, self.run_command,
'boot some-server --image 1 --key')
'boot some-server --flavor 1 --image 1 --key')
test_shell_call()
def test_boot_key_file(self):
testfile = os.path.join(os.path.dirname(__file__), 'testfile.txt')
expected_file_data = open(testfile).read().encode('base64')
self.run_command('boot some-server --image 1 --key %s' % testfile)
cmd = 'boot some-server --flavor 1 --image 1 --key %s'
self.run_command(cmd % testfile)
self.assert_called_anytime(
'POST', '/servers',
{'server': {
'flavorRef': 1,
'flavorRef': '1',
'name': 'some-server',
'imageRef': '1',
'min_count': 1,
@ -145,15 +148,16 @@ class ShellTest(utils.TestCase):
'personality': [
{'path': '/root/.ssh/authorized_keys2',
'contents':expected_file_data},
]}
}
]},
},
)
def test_boot_invalid_keyfile(self):
invalid_file = os.path.join(os.path.dirname(__file__),
'asdfasdfasdfasdf')
cmd = 'boot some-server --flavor 1 --image 1 --key %s'
self.assertRaises(exceptions.CommandError, self.run_command,
'boot some-server --image 1 --key %s' % invalid_file)
cmd % invalid_file)
def test_flavor_list(self):
self.run_command('flavor-list')
@ -177,7 +181,7 @@ class ShellTest(utils.TestCase):
# Suppress stdout and stderr
(stdout, stderr) = (sys.stdout, sys.stderr)
(sys.stdout, sys.stderr) = (tmp, tmp)
(sys.stdout, sys.stderr) = (tmp, tmp)
self.assertRaises(SystemExit, self.run_command,
'image-meta 1 BAD_ACTION test_key=test_value')
@ -193,7 +197,7 @@ class ShellTest(utils.TestCase):
self.run_command('image-create sample-server mysnapshot')
self.assert_called(
'POST', '/servers/1234/action',
{'createImage': {'name': 'mysnapshot', 'metadata': {}}}
{'createImage': {'name': 'mysnapshot', 'metadata': {}}},
)
def test_image_delete(self):
@ -225,7 +229,6 @@ class ShellTest(utils.TestCase):
# {'rebuild': {'imageRef': 1, 'adminPass': 'asdf'}})
self.assert_called('GET', '/images/2')
def test_rename(self):
self.run_command('rename sample-server newname')
self.assert_called('PUT', '/servers/1234',