
This change adds database support to the python-openstackclient through a plugin and tests. The support can be demonstrated through the implementation of the trove command flavor-list which is now: openstack database flavor list Use the -v or --debug flag to see the calls being made to the correct flavor list function. ubuntu@ubuntu:~$ openstack database flavor list -v START with options: [u'database', u'flavor', u'list', u'-v'] command: database flavor list -> troveclient.osc.v1.flavors.ListFlavors Using auth plugin: password +-----+-----------+-------+-------+------+-----------+ | id | name | RAM | vCPUs | Disk | ephemeral | +-----+-----------+-------+-------+------+-----------+ | 1 | m1.tiny | 512 | 1 | 1 | 0 | | 2 | m1.small | 2048 | 1 | 20 | 0 | | 3 | m1.medium | 4096 | 2 | 40 | 0 | | 4 | m1.large | 8192 | 4 | 80 | 0 | | 42 | m1.nano | 64 | 1 | 0 | 0 | | 451 | m1.heat | 512 | 1 | 0 | 0 | | 5 | m1.xlarge | 16384 | 8 | 160 | 0 | | 84 | m1.micro | 128 | 1 | 0 | 0 | | c1 | cirros256 | 256 | 1 | 0 | 0 | | d1 | ds512M | 512 | 1 | 5 | 0 | | d2 | ds1G | 1024 | 1 | 10 | 0 | | d3 | ds2G | 2048 | 2 | 10 | 0 | | d4 | ds4G | 4096 | 4 | 20 | 0 | +-----+-----------+-------+-------+------+-----------+ END return value: 0 Change-Id: I308a6c6f3f5ce7dbb814ec0fd8ecb1734a2f137f Partially-Implements: trove-support-in-python-openstackclient
63 lines
2.1 KiB
Python
63 lines
2.1 KiB
Python
# 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.
|
|
#
|
|
|
|
import os
|
|
|
|
import fixtures
|
|
import mock
|
|
import sys
|
|
import testtools
|
|
|
|
from troveclient.tests.osc import fakes
|
|
|
|
|
|
class TestCase(testtools.TestCase):
|
|
def setUp(self):
|
|
testtools.TestCase.setUp(self)
|
|
|
|
if (os.environ.get("OS_STDOUT_CAPTURE") == "True" or
|
|
os.environ.get("OS_STDOUT_CAPTURE") == "1"):
|
|
stdout = self.useFixture(fixtures.StringStream("stdout")).stream
|
|
self.useFixture(fixtures.MonkeyPatch("sys.stdout", stdout))
|
|
|
|
if (os.environ.get("OS_STDERR_CAPTURE") == "True" or
|
|
os.environ.get("OS_STDERR_CAPTURE") == "1"):
|
|
stderr = self.useFixture(fixtures.StringStream("stderr")).stream
|
|
self.useFixture(fixtures.MonkeyPatch("sys.stderr", stderr))
|
|
|
|
|
|
class TestCommand(TestCase):
|
|
"""Test cliff command classes"""
|
|
|
|
def setUp(self):
|
|
super(TestCommand, self).setUp()
|
|
# Build up a fake app
|
|
self.fake_stdout = fakes.FakeStdout()
|
|
self.app = mock.MagicMock()
|
|
self.app.stdout = self.fake_stdout
|
|
self.app.stdin = sys.stdin
|
|
self.app.stderr = sys.stderr
|
|
|
|
def check_parser(self, cmd, args, verify_args):
|
|
cmd_parser = cmd.get_parser('check_parser')
|
|
try:
|
|
parsed_args = cmd_parser.parse_args(args)
|
|
except SystemExit:
|
|
raise Exception("Argument parse failed")
|
|
for av in verify_args:
|
|
attr, value = av
|
|
if attr:
|
|
self.assertIn(attr, parsed_args)
|
|
self.assertEqual(getattr(parsed_args, attr), value)
|
|
return parsed_args
|