2013-08-06 13:36:45 -03:00
|
|
|
# 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.
|
|
|
|
|
2012-12-24 21:49:34 -06:00
|
|
|
import re
|
2012-05-21 16:32:35 -04:00
|
|
|
import sys
|
|
|
|
|
2012-12-24 21:49:34 -06:00
|
|
|
import fixtures
|
2013-06-12 08:28:17 -05:00
|
|
|
from six import moves
|
2012-12-24 21:49:34 -06:00
|
|
|
from testtools import matchers
|
|
|
|
|
2013-07-15 16:25:40 +00:00
|
|
|
from cinderclient import exceptions
|
2012-05-21 16:32:35 -04:00
|
|
|
import cinderclient.shell
|
2013-05-18 09:22:23 -07:00
|
|
|
from cinderclient.tests import utils
|
2012-05-21 16:32:35 -04:00
|
|
|
|
|
|
|
|
|
|
|
class ShellTest(utils.TestCase):
|
|
|
|
|
2012-12-24 21:49:34 -06:00
|
|
|
FAKE_ENV = {
|
|
|
|
'OS_USERNAME': 'username',
|
|
|
|
'OS_PASSWORD': 'password',
|
|
|
|
'OS_TENANT_NAME': 'tenant_name',
|
|
|
|
'OS_AUTH_URL': 'http://no.where',
|
|
|
|
}
|
|
|
|
|
2012-05-21 16:32:35 -04:00
|
|
|
# Patch os.environ to avoid required auth info.
|
|
|
|
def setUp(self):
|
2012-12-24 21:49:34 -06:00
|
|
|
super(ShellTest, self).setUp()
|
|
|
|
for var in self.FAKE_ENV:
|
|
|
|
self.useFixture(fixtures.EnvironmentVariable(var,
|
|
|
|
self.FAKE_ENV[var]))
|
2012-05-21 16:32:35 -04:00
|
|
|
|
|
|
|
def shell(self, argstr):
|
|
|
|
orig = sys.stdout
|
|
|
|
try:
|
2013-06-12 08:28:17 -05:00
|
|
|
sys.stdout = moves.StringIO()
|
2012-05-21 16:32:35 -04:00
|
|
|
_shell = cinderclient.shell.OpenStackCinderShell()
|
|
|
|
_shell.main(argstr.split())
|
|
|
|
except SystemExit:
|
|
|
|
exc_type, exc_value, exc_traceback = sys.exc_info()
|
|
|
|
self.assertEqual(exc_value.code, 0)
|
|
|
|
finally:
|
|
|
|
out = sys.stdout.getvalue()
|
|
|
|
sys.stdout.close()
|
|
|
|
sys.stdout = orig
|
|
|
|
|
|
|
|
return out
|
|
|
|
|
|
|
|
def test_help_unknown_command(self):
|
|
|
|
self.assertRaises(exceptions.CommandError, self.shell, 'help foofoo')
|
|
|
|
|
|
|
|
def test_help(self):
|
|
|
|
required = [
|
2012-12-24 21:49:34 -06:00
|
|
|
'.*?^usage: ',
|
|
|
|
'.*?(?m)^\s+create\s+Add a new volume.',
|
|
|
|
'.*?(?m)^See "cinder help COMMAND" for help on a specific command',
|
2012-05-21 16:32:35 -04:00
|
|
|
]
|
2012-11-08 23:33:14 +01:00
|
|
|
help_text = self.shell('help')
|
|
|
|
for r in required:
|
2012-12-24 21:49:34 -06:00
|
|
|
self.assertThat(help_text,
|
2013-01-16 15:45:29 +02:00
|
|
|
matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))
|
2012-05-21 16:32:35 -04:00
|
|
|
|
|
|
|
def test_help_on_subcommand(self):
|
|
|
|
required = [
|
2012-12-24 21:49:34 -06:00
|
|
|
'.*?^usage: cinder list',
|
|
|
|
'.*?(?m)^List all the volumes.',
|
2012-05-21 16:32:35 -04:00
|
|
|
]
|
2012-11-08 23:33:14 +01:00
|
|
|
help_text = self.shell('help list')
|
|
|
|
for r in required:
|
2012-12-24 21:49:34 -06:00
|
|
|
self.assertThat(help_text,
|
2013-01-16 15:45:29 +02:00
|
|
|
matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))
|