2012-11-01 13:41:32 +01:00
|
|
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
|
|
|
|
2013-03-11 14:49:31 -04:00
|
|
|
# Copyright 2011 OpenStack Foundation.
|
2012-11-01 13:41:32 +01:00
|
|
|
# All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License. You may obtain
|
|
|
|
# a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
|
|
|
|
from openstack.common import processutils
|
2013-01-23 09:59:46 -05:00
|
|
|
from tests import utils
|
2012-11-01 13:41:32 +01:00
|
|
|
|
|
|
|
|
2013-01-23 09:59:46 -05:00
|
|
|
class UtilsTest(utils.BaseTestCase):
|
2012-11-01 13:41:32 +01:00
|
|
|
# NOTE(jkoelker) Moar tests from nova need to be ported. But they
|
|
|
|
# need to be mock'd out. Currently they requre actually
|
|
|
|
# running code.
|
|
|
|
def test_execute_unknown_kwargs(self):
|
|
|
|
self.assertRaises(processutils.UnknownArgumentError,
|
|
|
|
processutils.execute,
|
|
|
|
hozer=True)
|
|
|
|
|
|
|
|
|
2013-01-23 09:59:46 -05:00
|
|
|
class ProcessExecutionErrorTest(utils.BaseTestCase):
|
2012-11-01 13:41:32 +01:00
|
|
|
|
|
|
|
def test_defaults(self):
|
|
|
|
err = processutils.ProcessExecutionError()
|
|
|
|
self.assertTrue('None\n' in err.message)
|
|
|
|
self.assertTrue('code: -\n' in err.message)
|
|
|
|
|
|
|
|
def test_with_description(self):
|
|
|
|
description = 'The Narwhal Bacons at Midnight'
|
|
|
|
err = processutils.ProcessExecutionError(description=description)
|
|
|
|
self.assertTrue(description in err.message)
|
|
|
|
|
|
|
|
def test_with_exit_code(self):
|
|
|
|
exit_code = 0
|
|
|
|
err = processutils.ProcessExecutionError(exit_code=exit_code)
|
|
|
|
self.assertTrue(str(exit_code) in err.message)
|
|
|
|
|
|
|
|
def test_with_cmd(self):
|
|
|
|
cmd = 'telinit'
|
|
|
|
err = processutils.ProcessExecutionError(cmd=cmd)
|
|
|
|
self.assertTrue(cmd in err.message)
|
|
|
|
|
|
|
|
def test_with_stdout(self):
|
|
|
|
stdout = """
|
|
|
|
Lo, praise of the prowess of people-kings
|
|
|
|
of spear-armed Danes, in days long sped,
|
|
|
|
we have heard, and what honot the athelings won!
|
|
|
|
Oft Scyld the Scefing from squadroned foes,
|
|
|
|
from many a tribe, the mead-bench tore,
|
|
|
|
awing the earls. Since erse he lay
|
|
|
|
friendless, a foundling, fate repaid him:
|
|
|
|
for he waxed under welkin, in wealth he trove,
|
|
|
|
till before him the folk, both far and near,
|
|
|
|
who house by the whale-path, heard his mandate,
|
|
|
|
gabe him gits: a good king he!
|
|
|
|
To him an heir was afterward born,
|
|
|
|
a son in his halls, whom heaven sent
|
|
|
|
to favor the fol, feeling their woe
|
|
|
|
that erst they had lacked an earl for leader
|
|
|
|
so long a while; the Lord endowed him,
|
|
|
|
the Wielder of Wonder, with world's renown.
|
|
|
|
""".strip()
|
|
|
|
err = processutils.ProcessExecutionError(stdout=stdout)
|
2013-04-22 03:42:48 +02:00
|
|
|
print(err.message)
|
2012-11-01 13:41:32 +01:00
|
|
|
self.assertTrue('people-kings' in err.message)
|
|
|
|
|
|
|
|
def test_with_stderr(self):
|
|
|
|
stderr = 'Cottonian library'
|
|
|
|
err = processutils.ProcessExecutionError(stderr=stderr)
|
|
|
|
self.assertTrue(stderr in str(err.message))
|