Fix backwards compatibility for v1 API imports

All python modules in "manilaclient/v1" override v2 modules with v2 modules
and v1 modules do not provide APIs at all. So, fix those imports and add
test coverage.

Change-Id: I24835745d028fa50252207cb02304e73657696e5
Closes-Bug: #1535692
This commit is contained in:
vponomaryov 2016-01-19 14:21:23 +02:00
parent 37dc7e8ebd
commit e2b825cc69
24 changed files with 396 additions and 12 deletions

View File

@ -0,0 +1,32 @@
# Copyright 2016 Mirantis Inc.
# 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.
import six
from manilaclient.tests.unit import utils
class LimitsV1Test(utils.TestCase):
def test_import_v1_limits_module(self):
try:
from manilaclient.v1 import limits
except Exception as e:
msg = ("module 'manilaclient.v1.limits' cannot be imported "
"with error: %s") % six.text_type(e)
assert False, msg
for cls in ('Limits', 'RateLimit', 'AbsoluteLimit', 'LimitsManager'):
msg = "Module 'limits' has no '%s' attr." % cls
self.assertTrue(hasattr(limits, cls), msg)

View File

@ -0,0 +1,32 @@
# Copyright 2016 Mirantis Inc.
# 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.
import six
from manilaclient.tests.unit import utils
class QuotaClassesV1Test(utils.TestCase):
def test_import_v1_quota_classes_module(self):
try:
from manilaclient.v1 import quota_classes
except Exception as e:
msg = ("module 'manilaclient.v1.quota_classes' cannot be imported "
"with error: %s") % six.text_type(e)
assert False, msg
for cls in ('QuotaClassSet', 'QuotaClassSetManager'):
msg = "Module 'quota_classes' has no '%s' attr." % cls
self.assertTrue(hasattr(quota_classes, cls), msg)

View File

@ -0,0 +1,32 @@
# Copyright 2016 Mirantis Inc.
# 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.
import six
from manilaclient.tests.unit import utils
class QuotasV1Test(utils.TestCase):
def test_import_v1_quotas_module(self):
try:
from manilaclient.v1 import quotas
except Exception as e:
msg = ("module 'manilaclient.v1.quotas' cannot be imported "
"with error: %s") % six.text_type(e)
assert False, msg
for cls in ('QuotaSet', 'QuotaSetManager'):
msg = "Module 'quotas' has no '%s' attr." % cls
self.assertTrue(hasattr(quotas, cls), msg)

View File

@ -0,0 +1,32 @@
# Copyright 2016 Mirantis Inc.
# 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.
import six
from manilaclient.tests.unit import utils
class SchedulerStatsV1Test(utils.TestCase):
def test_import_v1_scheduler_stats_module(self):
try:
from manilaclient.v1 import scheduler_stats
except Exception as e:
msg = ("module 'manilaclient.v1.scheduler_stats' cannot be "
"imported with error: %s") % six.text_type(e)
assert False, msg
for cls in ('Pool', 'PoolManager'):
msg = "Module 'scheduler_stats' has no '%s' attr." % cls
self.assertTrue(hasattr(scheduler_stats, cls), msg)

View File

@ -0,0 +1,32 @@
# Copyright 2016 Mirantis Inc.
# 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.
import six
from manilaclient.tests.unit import utils
class SecurityServicesV1Test(utils.TestCase):
def test_import_v1_security_services_module(self):
try:
from manilaclient.v1 import security_services
except Exception as e:
msg = ("module 'manilaclient.v1.security_services' cannot be "
"imported with error: %s") % six.text_type(e)
assert False, msg
for cls in ('SecurityService', 'SecurityServiceManager'):
msg = "Module 'security_services' has no '%s' attr." % cls
self.assertTrue(hasattr(security_services, cls), msg)

View File

@ -0,0 +1,32 @@
# Copyright 2016 Mirantis Inc.
# 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.
import six
from manilaclient.tests.unit import utils
class ServicesV1Test(utils.TestCase):
def test_import_v1_services_module(self):
try:
from manilaclient.v1 import services
except Exception as e:
msg = ("module 'manilaclient.v1.services' cannot be imported "
"with error: %s") % six.text_type(e)
assert False, msg
for cls in ('Service', 'ServiceManager'):
msg = "Module 'services' has no '%s' attr." % cls
self.assertTrue(hasattr(services, cls), msg)

View File

@ -0,0 +1,32 @@
# Copyright 2016 Mirantis Inc.
# 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.
import six
from manilaclient.tests.unit import utils
class ShareNetworksV1Test(utils.TestCase):
def test_import_v1_share_networks_module(self):
try:
from manilaclient.v1 import share_networks
except Exception as e:
msg = ("module 'manilaclient.v1.share_networks' cannot be "
"imported with error: %s") % six.text_type(e)
assert False, msg
for cls in ('ShareNetwork', 'ShareNetworkManager'):
msg = "Module 'share_networks' has no '%s' attr." % cls
self.assertTrue(hasattr(share_networks, cls), msg)

View File

@ -0,0 +1,32 @@
# Copyright 2016 Mirantis Inc.
# 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.
import six
from manilaclient.tests.unit import utils
class ShareServersV1Test(utils.TestCase):
def test_import_v1_share_servers_module(self):
try:
from manilaclient.v1 import share_servers
except Exception as e:
msg = ("module 'manilaclient.v1.share_servers' cannot be imported "
"with error: %s") % six.text_type(e)
assert False, msg
for cls in ('ShareServer', 'ShareServerManager'):
msg = "Module 'share_servers' has no '%s' attr." % cls
self.assertTrue(hasattr(share_servers, cls), msg)

View File

@ -0,0 +1,32 @@
# Copyright 2016 Mirantis Inc.
# 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.
import six
from manilaclient.tests.unit import utils
class ShareSnapshotsV1Test(utils.TestCase):
def test_import_v1_share_snapshots_module(self):
try:
from manilaclient.v1 import share_snapshots
except Exception as e:
msg = ("module 'manilaclient.v1.share_snapshots' cannot be "
"imported with error: %s") % six.text_type(e)
assert False, msg
for cls in ('ShareSnapshot', 'ShareSnapshotManager'):
msg = "Module 'share_snapshots' has no '%s' attr." % cls
self.assertTrue(hasattr(share_snapshots, cls), msg)

View File

@ -0,0 +1,32 @@
# Copyright 2016 Mirantis Inc.
# 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.
import six
from manilaclient.tests.unit import utils
class ShareTypeAccessV1Test(utils.TestCase):
def test_import_v1_share_type_access_module(self):
try:
from manilaclient.v1 import share_type_access
except Exception as e:
msg = ("module 'manilaclient.v1.share_type_access' cannot be "
"imported with error: %s") % six.text_type(e)
assert False, msg
for cls in ('ShareTypeAccess', 'ShareTypeAccessManager'):
msg = "Module 'share_type_access' has no '%s' attr." % cls
self.assertTrue(hasattr(share_type_access, cls), msg)

View File

@ -0,0 +1,32 @@
# Copyright 2016 Mirantis Inc.
# 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.
import six
from manilaclient.tests.unit import utils
class ShareTypesV1Test(utils.TestCase):
def test_import_v1_share_types_module(self):
try:
from manilaclient.v1 import share_types
except Exception as e:
msg = ("module 'manilaclient.v1.share_types' cannot be imported "
"with error: %s") % six.text_type(e)
assert False, msg
for cls in ('ShareType', 'ShareTypeManager'):
msg = "Module 'share_types' has no '%s' attr." % cls
self.assertTrue(hasattr(share_types, cls), msg)

View File

@ -0,0 +1,32 @@
# Copyright 2016 Mirantis Inc.
# 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.
import six
from manilaclient.tests.unit import utils
class SharesV1Test(utils.TestCase):
def test_import_v1_shares_module(self):
try:
from manilaclient.v1 import shares
except Exception as e:
msg = ("module 'manilaclient.v1.shares' cannot be imported "
"with error: %s") % six.text_type(e)
assert False, msg
for cls in ('Share', 'ShareManager'):
msg = "Module 'shares' has no '%s' attr." % cls
self.assertTrue(hasattr(shares, cls), msg)

View File

@ -32,4 +32,4 @@ class MovedModule(object):
def __getattr__(self, attr): def __getattr__(self, attr):
return getattr(self.new_module, attr) return getattr(self.new_module, attr)
sys.modules["manilaclient.v2.limits"] = MovedModule(limits) sys.modules["manilaclient.v1.limits"] = MovedModule(limits)

View File

@ -32,4 +32,4 @@ class MovedModule(object):
def __getattr__(self, attr): def __getattr__(self, attr):
return getattr(self.new_module, attr) return getattr(self.new_module, attr)
sys.modules["manilaclient.v2.quota_classes"] = MovedModule(quota_classes) sys.modules["manilaclient.v1.quota_classes"] = MovedModule(quota_classes)

View File

@ -32,4 +32,4 @@ class MovedModule(object):
def __getattr__(self, attr): def __getattr__(self, attr):
return getattr(self.new_module, attr) return getattr(self.new_module, attr)
sys.modules["manilaclient.v2.quotas"] = MovedModule(quotas) sys.modules["manilaclient.v1.quotas"] = MovedModule(quotas)

View File

@ -32,4 +32,4 @@ class MovedModule(object):
def __getattr__(self, attr): def __getattr__(self, attr):
return getattr(self.new_module, attr) return getattr(self.new_module, attr)
sys.modules["manilaclient.v2.scheduler_stats"] = MovedModule(scheduler_stats) sys.modules["manilaclient.v1.scheduler_stats"] = MovedModule(scheduler_stats)

View File

@ -33,4 +33,4 @@ class MovedModule(object):
return getattr(self.new_module, attr) return getattr(self.new_module, attr)
sys.modules[ sys.modules[
"manilaclient.v2.security_services"] = MovedModule(security_services) "manilaclient.v1.security_services"] = MovedModule(security_services)

View File

@ -32,4 +32,4 @@ class MovedModule(object):
def __getattr__(self, attr): def __getattr__(self, attr):
return getattr(self.new_module, attr) return getattr(self.new_module, attr)
sys.modules["manilaclient.v2.services"] = MovedModule(services) sys.modules["manilaclient.v1.services"] = MovedModule(services)

View File

@ -32,4 +32,4 @@ class MovedModule(object):
def __getattr__(self, attr): def __getattr__(self, attr):
return getattr(self.new_module, attr) return getattr(self.new_module, attr)
sys.modules["manilaclient.v2.share_networks"] = MovedModule(share_networks) sys.modules["manilaclient.v1.share_networks"] = MovedModule(share_networks)

View File

@ -32,4 +32,4 @@ class MovedModule(object):
def __getattr__(self, attr): def __getattr__(self, attr):
return getattr(self.new_module, attr) return getattr(self.new_module, attr)
sys.modules["manilaclient.v2.share_servers"] = MovedModule(share_servers) sys.modules["manilaclient.v1.share_servers"] = MovedModule(share_servers)

View File

@ -32,4 +32,4 @@ class MovedModule(object):
def __getattr__(self, attr): def __getattr__(self, attr):
return getattr(self.new_module, attr) return getattr(self.new_module, attr)
sys.modules["manilaclient.v2.share_snapshots"] = MovedModule(share_snapshots) sys.modules["manilaclient.v1.share_snapshots"] = MovedModule(share_snapshots)

View File

@ -33,4 +33,4 @@ class MovedModule(object):
return getattr(self.new_module, attr) return getattr(self.new_module, attr)
sys.modules[ sys.modules[
"manilaclient.v2.share_type_access"] = MovedModule(share_type_access) "manilaclient.v1.share_type_access"] = MovedModule(share_type_access)

View File

@ -32,4 +32,4 @@ class MovedModule(object):
def __getattr__(self, attr): def __getattr__(self, attr):
return getattr(self.new_module, attr) return getattr(self.new_module, attr)
sys.modules["manilaclient.v2.share_types"] = MovedModule(share_types) sys.modules["manilaclient.v1.share_types"] = MovedModule(share_types)

View File

@ -32,4 +32,4 @@ class MovedModule(object):
def __getattr__(self, attr): def __getattr__(self, attr):
return getattr(self.new_module, attr) return getattr(self.new_module, attr)
sys.modules["manilaclient.v2.shares"] = MovedModule(shares) sys.modules["manilaclient.v1.shares"] = MovedModule(shares)