diff --git a/.pylintrc b/.pylintrc index 2a7779a..633018d 100644 --- a/.pylintrc +++ b/.pylintrc @@ -171,7 +171,7 @@ ignored-modules= # List of class names for which member attributes should not be checked (useful # for classes with dynamically set attributes). This supports the use of # qualified names. -ignored-classes=optparse.Values,thread._local,_thread._local, hnv_client.common.model.Model +ignored-classes=optparse.Values,thread._local,_thread._local, hnv.common.model.Model # List of members which are set dynamically and missed by pylint inference # system, and so shouldn't trigger E1101 when accessed. Python regular diff --git a/.testr.conf b/.testr.conf index 4da1d9c..cd93f45 100644 --- a/.testr.conf +++ b/.testr.conf @@ -2,7 +2,7 @@ test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \ OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \ OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-160} \ - ${PYTHON:-python} -m subunit.run discover -t ./ ./hnv_client/tests $LISTOPT $IDOPTION + ${PYTHON:-python} -m subunit.run discover -t ./ ./hnv/tests $LISTOPT $IDOPTION test_id_option=--load-list $IDFILE test_list_option=--list diff --git a/README.md b/README.md index 940c79c..1ba1542 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# hvn-client +# python-hnv Python client for the HNV (Hyper-V Network Virtualization) REST API. diff --git a/doc/source/client.rst b/doc/source/client.rst index c58b010..78e9b21 100644 --- a/doc/source/client.rst +++ b/doc/source/client.rst @@ -1,7 +1,7 @@ HNV Client ========== -.. automodule:: hnv_client.client +.. automodule:: hnv.client :members: :inherited-members: .. autoattribute:: diff --git a/doc/source/exceptions.rst b/doc/source/exceptions.rst index 6e81622..14008c6 100644 --- a/doc/source/exceptions.rst +++ b/doc/source/exceptions.rst @@ -1,6 +1,6 @@ HNV Client's exceptions ======================= -.. automodule:: hnv_client.common.exception +.. automodule:: hnv.common.exception :members: .. autoattribute:: diff --git a/etc/hnv/README.md b/etc/hnv/README.md new file mode 100644 index 0000000..64467f4 --- /dev/null +++ b/etc/hnv/README.md @@ -0,0 +1,4 @@ +To generate the sample hnv.conf file, run the following command from the top +level of the python-hnv directory: + + oslo-config-generator --config-file etc/python-hnv/hnv-config-generator.conf diff --git a/etc/hnv/hnv_client-config-generator.conf b/etc/hnv/hnv_client-config-generator.conf new file mode 100644 index 0000000..09727e1 --- /dev/null +++ b/etc/hnv/hnv_client-config-generator.conf @@ -0,0 +1,5 @@ +[DEFAULT] +output_file = etc/python-hnv/hnv.conf +wrap_width = 80 +namespace = hnv.conf +namespace = oslo.log diff --git a/etc/hnv_client/README.md b/etc/hnv_client/README.md deleted file mode 100644 index 8fe9829..0000000 --- a/etc/hnv_client/README.md +++ /dev/null @@ -1,4 +0,0 @@ -To generate the sample hnv_client.conf file, run the following command from the top -level of the arestor directory: - - oslo-config-generator --config-file etc/hnv_client/hnv_client-config-generator.conf diff --git a/etc/hnv_client/hnv_client-config-generator.conf b/etc/hnv_client/hnv_client-config-generator.conf deleted file mode 100644 index 28cd949..0000000 --- a/etc/hnv_client/hnv_client-config-generator.conf +++ /dev/null @@ -1,5 +0,0 @@ -[DEFAULT] -output_file = etc/hnv_client/hnv_client.conf -wrap_width = 80 -namespace = hnv_client -namespace = oslo.log diff --git a/hnv_client/__init__.py b/hnv/__init__.py similarity index 100% rename from hnv_client/__init__.py rename to hnv/__init__.py diff --git a/hnv_client/client.py b/hnv/client.py similarity index 99% rename from hnv_client/client.py rename to hnv/client.py index b774846..abd4fe1 100644 --- a/hnv_client/client.py +++ b/hnv/client.py @@ -19,11 +19,11 @@ import uuid from oslo_log import log as logging -from hnv_client.common import constant -from hnv_client.common import exception -from hnv_client.common import model -from hnv_client.common import utils -from hnv_client import config as hnv_config +from hnv.common import constant +from hnv.common import exception +from hnv.common import model +from hnv.common import utils +from hnv import config as hnv_config LOG = logging.getLogger(__name__) CONFIG = hnv_config.CONFIG diff --git a/hnv_client/common/__init__.py b/hnv/common/__init__.py similarity index 100% rename from hnv_client/common/__init__.py rename to hnv/common/__init__.py diff --git a/hnv_client/common/constant.py b/hnv/common/constant.py similarity index 100% rename from hnv_client/common/constant.py rename to hnv/common/constant.py diff --git a/hnv_client/common/exception.py b/hnv/common/exception.py similarity index 98% rename from hnv_client/common/exception.py rename to hnv/common/exception.py index c1855c4..75b578f 100644 --- a/hnv_client/common/exception.py +++ b/hnv/common/exception.py @@ -17,7 +17,7 @@ class HNVException(Exception): - """Base hnv_client exception. + """Base HNV client exception. To correctly use this class, inherit from it and define a `template` property. diff --git a/hnv_client/common/model.py b/hnv/common/model.py similarity index 99% rename from hnv_client/common/model.py rename to hnv/common/model.py index 633bd32..676ae57 100644 --- a/hnv_client/common/model.py +++ b/hnv/common/model.py @@ -21,7 +21,7 @@ import copy from oslo_log import log as logging import six -from hnv_client.common import exception +from hnv.common import exception LOG = logging.getLogger(__name__) diff --git a/hnv_client/common/utils.py b/hnv/common/utils.py similarity index 98% rename from hnv_client/common/utils.py rename to hnv/common/utils.py index 5f38617..de1783e 100644 --- a/hnv_client/common/utils.py +++ b/hnv/common/utils.py @@ -23,9 +23,9 @@ import requests import requests_ntlm import six -from hnv_client.common import constant -from hnv_client.common import exception -from hnv_client import config as hnv_config +from hnv.common import constant +from hnv.common import exception +from hnv import config as hnv_config LOG = logging.getLogger(__name__) CONFIG = hnv_config.CONFIG diff --git a/hnv_client/config/__init__.py b/hnv/config/__init__.py similarity index 88% rename from hnv_client/config/__init__.py rename to hnv/config/__init__.py index 529dd20..ce98fa1 100644 --- a/hnv_client/config/__init__.py +++ b/hnv/config/__init__.py @@ -16,9 +16,9 @@ from oslo_config import cfg -from hnv_client.config import factory +from hnv.config import factory as options_factory CONFIG = cfg.CONF -for option_class in factory.get_options(): +for option_class in options_factory.get_options(): option_class(CONFIG).register() diff --git a/hnv_client/config/base.py b/hnv/config/base.py similarity index 100% rename from hnv_client/config/base.py rename to hnv/config/base.py diff --git a/hnv_client/config/hnv.py b/hnv/config/client.py similarity index 98% rename from hnv_client/config/hnv.py rename to hnv/config/client.py index eae8927..f0ebb14 100644 --- a/hnv_client/config/hnv.py +++ b/hnv/config/client.py @@ -16,7 +16,7 @@ from oslo_config import cfg -from hnv_client.config import base as config_base +from hnv.config import base as config_base class HVNOptions(config_base.Options): diff --git a/hnv_client/config/factory.py b/hnv/config/factory.py similarity index 96% rename from hnv_client/config/factory.py rename to hnv/config/factory.py index 7f1d667..496e22c 100644 --- a/hnv_client/config/factory.py +++ b/hnv/config/factory.py @@ -15,7 +15,7 @@ """Factory for all the available config options.""" _OPT_PATHS = ( - 'hnv_client.config.hnv.HVNOptions', + 'hnv.config.client.HVNOptions', ) diff --git a/hnv_client/config/options.py b/hnv/config/options.py similarity index 91% rename from hnv_client/config/options.py rename to hnv/config/options.py index ea78abf..440c7c4 100644 --- a/hnv_client/config/options.py +++ b/hnv/config/options.py @@ -19,8 +19,8 @@ file for Cloudbase-Init. import collections -from hnv_client.config import base as config_base -from hnv_client.config import factory as config_factory +from hnv.config import base as config_base +from hnv.config import factory as config_factory def get_options(): diff --git a/hnv_client/tests/__init__.py b/hnv/tests/__init__.py similarity index 100% rename from hnv_client/tests/__init__.py rename to hnv/tests/__init__.py diff --git a/hnv_client/tests/common/__init__.py b/hnv/tests/common/__init__.py similarity index 100% rename from hnv_client/tests/common/__init__.py rename to hnv/tests/common/__init__.py diff --git a/hnv_client/tests/common/test_model.py b/hnv/tests/common/test_model.py similarity index 97% rename from hnv_client/tests/common/test_model.py rename to hnv/tests/common/test_model.py index be33129..6221647 100644 --- a/hnv_client/tests/common/test_model.py +++ b/hnv/tests/common/test_model.py @@ -21,8 +21,8 @@ try: except ImportError: import mock -from hnv_client.common import exception -from hnv_client.common import model +from hnv.common import exception +from hnv.common import model class TestFieldDescriptor(unittest.TestCase): @@ -80,7 +80,7 @@ class TestField(unittest.TestCase): self.assertIs(field.is_property, mock.sentinel.is_property) self.assertIs(field.is_read_only, mock.sentinel.is_read_only) - @mock.patch("hnv_client.common.model._FieldDescriptor") + @mock.patch("hnv.common.model._FieldDescriptor") def test_add_to_class(self, mock_field_descriptor): field = model.Field(name="test_add_to_class", key="test") model_class = mock.Mock() @@ -101,7 +101,7 @@ class TestModelOptions(unittest.TestCase): self.assertEqual(model_options._name, mock.sentinel.cls.name) @mock.patch("six.callable") - @mock.patch("hnv_client.common.model._ModelOptions.remove_field") + @mock.patch("hnv.common.model._ModelOptions.remove_field") def _test_add_field(self, mock_remove_field, mock_callable, callable_default): model_options = model._ModelOptions(self.__class__) diff --git a/hnv_client/tests/common/test_utils.py b/hnv/tests/common/test_utils.py similarity index 93% rename from hnv_client/tests/common/test_utils.py rename to hnv/tests/common/test_utils.py index 43b9a86..574d878 100644 --- a/hnv_client/tests/common/test_utils.py +++ b/hnv/tests/common/test_utils.py @@ -22,11 +22,11 @@ except ImportError: import requests -from hnv_client.common import constant -from hnv_client.common import exception -from hnv_client.common import utils as hnv_utils -from hnv_client import config as hnv_config -from hnv_client.tests import utils as test_utils +from hnv.common import constant +from hnv.common import exception +from hnv.common import utils as hnv_utils +from hnv import config as hnv_config +from hnv.tests import utils as test_utils CONFIG = hnv_config.CONFIG @@ -41,8 +41,8 @@ class TestHNVClient(unittest.TestCase): return hnv_utils._HNVClient(url, username, password, allow_insecure, ca_bundle) - @mock.patch("hnv_client.common.utils._HNVClient._get_headers") - @mock.patch("hnv_client.common.utils._HNVClient._verify_https_request") + @mock.patch("hnv.common.utils._HNVClient._get_headers") + @mock.patch("hnv.common.utils._HNVClient._verify_https_request") @mock.patch("requests_ntlm.HttpNtlmAuth") @mock.patch("requests.Session") def test_session(self, mock_get_session, mock_auth, mock_verify, @@ -75,8 +75,8 @@ class TestHNVClient(unittest.TestCase): @mock.patch("time.sleep") @mock.patch("json.dumps") @mock.patch("requests.compat.urljoin") - @mock.patch("hnv_client.common.utils._HNVClient._session") - @mock.patch("hnv_client.common.utils._HNVClient._get_headers") + @mock.patch("hnv.common.utils._HNVClient._session") + @mock.patch("hnv.common.utils._HNVClient._get_headers") def _test_http_request(self, mock_headers, mock_session, mock_join, mock_dump, mock_sleep, method, body, response, status_code): @@ -101,7 +101,7 @@ class TestHNVClient(unittest.TestCase): {"status_code": status_code}) client = self._get_client() - with test_utils.LogSnatcher("hnv_client.common.utils") as logging: + with test_utils.LogSnatcher("hnv.common.utils") as logging: if isinstance(expected_response, requests.exceptions.SSLError): self.assertRaises(exception.CertificateVerifyFailed, client._http_request, @@ -209,7 +209,7 @@ class TestHNVClient(unittest.TestCase): response=response, status_code=500) - @mock.patch("hnv_client.common.utils._HNVClient._http_request") + @mock.patch("hnv.common.utils._HNVClient._http_request") def test_get_resource(self, mock_http_request): response = mock.Mock() response.json = mock.Mock() @@ -224,7 +224,7 @@ class TestHNVClient(unittest.TestCase): self.assertRaises(exception.ServiceException, client.get_resource, mock.sentinel.path) - @mock.patch("hnv_client.common.utils._HNVClient._http_request") + @mock.patch("hnv.common.utils._HNVClient._http_request") def test_update_resource(self, mock_http_request): response = mock.Mock() response.json = mock.Mock() @@ -243,7 +243,7 @@ class TestHNVClient(unittest.TestCase): client.update_resource, mock.sentinel.path, mock.sentinel.data) - @mock.patch("hnv_client.common.utils._HNVClient._http_request") + @mock.patch("hnv.common.utils._HNVClient._http_request") def test_remove_resource(self, mock_http_request): mock_http_request.return_value = mock.sentinel.response diff --git a/hnv_client/tests/fake/__init__.py b/hnv/tests/fake/__init__.py similarity index 100% rename from hnv_client/tests/fake/__init__.py rename to hnv/tests/fake/__init__.py diff --git a/hnv_client/tests/fake/fake_response.py b/hnv/tests/fake/fake_response.py similarity index 97% rename from hnv_client/tests/fake/fake_response.py rename to hnv/tests/fake/fake_response.py index caf9421..deb9b7a 100644 --- a/hnv_client/tests/fake/fake_response.py +++ b/hnv/tests/fake/fake_response.py @@ -23,7 +23,7 @@ class FakeResponse(object): """HNV API fake responses.""" def __init__(self): - self._resources = "hnv_client.tests.fake.response" + self._resources = "hnv.tests.fake.response" self._cache = {} def _load_resource(self, resource): diff --git a/hnv_client/tests/fake/response/__init__.py b/hnv/tests/fake/response/__init__.py similarity index 100% rename from hnv_client/tests/fake/response/__init__.py rename to hnv/tests/fake/response/__init__.py diff --git a/hnv_client/tests/fake/response/acl.json b/hnv/tests/fake/response/acl.json similarity index 100% rename from hnv_client/tests/fake/response/acl.json rename to hnv/tests/fake/response/acl.json diff --git a/hnv_client/tests/fake/response/acl_rules.json b/hnv/tests/fake/response/acl_rules.json similarity index 100% rename from hnv_client/tests/fake/response/acl_rules.json rename to hnv/tests/fake/response/acl_rules.json diff --git a/hnv_client/tests/fake/response/ip_configurations.json b/hnv/tests/fake/response/ip_configurations.json similarity index 100% rename from hnv_client/tests/fake/response/ip_configurations.json rename to hnv/tests/fake/response/ip_configurations.json diff --git a/hnv_client/tests/fake/response/ip_pools.json b/hnv/tests/fake/response/ip_pools.json similarity index 100% rename from hnv_client/tests/fake/response/ip_pools.json rename to hnv/tests/fake/response/ip_pools.json diff --git a/hnv_client/tests/fake/response/logical_networks.json b/hnv/tests/fake/response/logical_networks.json similarity index 100% rename from hnv_client/tests/fake/response/logical_networks.json rename to hnv/tests/fake/response/logical_networks.json diff --git a/hnv_client/tests/fake/response/logical_subnets.json b/hnv/tests/fake/response/logical_subnets.json similarity index 100% rename from hnv_client/tests/fake/response/logical_subnets.json rename to hnv/tests/fake/response/logical_subnets.json diff --git a/hnv_client/tests/fake/response/network_interfaces.json b/hnv/tests/fake/response/network_interfaces.json similarity index 100% rename from hnv_client/tests/fake/response/network_interfaces.json rename to hnv/tests/fake/response/network_interfaces.json diff --git a/hnv_client/tests/fake/response/route_tables.json b/hnv/tests/fake/response/route_tables.json similarity index 100% rename from hnv_client/tests/fake/response/route_tables.json rename to hnv/tests/fake/response/route_tables.json diff --git a/hnv_client/tests/fake/response/routes.json b/hnv/tests/fake/response/routes.json similarity index 100% rename from hnv_client/tests/fake/response/routes.json rename to hnv/tests/fake/response/routes.json diff --git a/hnv_client/tests/fake/response/virtual_networks.json b/hnv/tests/fake/response/virtual_networks.json similarity index 100% rename from hnv_client/tests/fake/response/virtual_networks.json rename to hnv/tests/fake/response/virtual_networks.json diff --git a/hnv_client/tests/fake/response/virtual_subnetworks.json b/hnv/tests/fake/response/virtual_subnetworks.json similarity index 100% rename from hnv_client/tests/fake/response/virtual_subnetworks.json rename to hnv/tests/fake/response/virtual_subnetworks.json diff --git a/hnv_client/tests/fake/response/virtual_switch_manager.json b/hnv/tests/fake/response/virtual_switch_manager.json similarity index 100% rename from hnv_client/tests/fake/response/virtual_switch_manager.json rename to hnv/tests/fake/response/virtual_switch_manager.json diff --git a/hnv_client/tests/test_client.py b/hnv/tests/test_client.py similarity index 93% rename from hnv_client/tests/test_client.py rename to hnv/tests/test_client.py index 65291bd..d77596a 100644 --- a/hnv_client/tests/test_client.py +++ b/hnv/tests/test_client.py @@ -21,12 +21,12 @@ try: except ImportError: import mock -from hnv_client import client -from hnv_client.common import constant -from hnv_client.common import exception -from hnv_client import config as hnv_config -from hnv_client.tests.fake import fake_response -from hnv_client.tests import utils as test_utils +from hnv import client +from hnv.common import constant +from hnv.common import exception +from hnv import config as hnv_config +from hnv.tests.fake import fake_response +from hnv.tests import utils as test_utils CONFIG = hnv_config.CONFIG @@ -36,8 +36,8 @@ class TestBaseHNVModel(unittest.TestCase): def setUp(self): client._BaseHNVModel._endpoint = "{parent_id}/{resource_id}" - @mock.patch("hnv_client.client._BaseHNVModel.from_raw_data") - @mock.patch("hnv_client.client._BaseHNVModel._get_client") + @mock.patch("hnv.client._BaseHNVModel.from_raw_data") + @mock.patch("hnv.client._BaseHNVModel._get_client") def test_get(self, mock_get_client, mock_from_raw_data): mock_from_raw_data.return_value = mock.sentinel.resource http_client = mock_get_client.return_value = mock.Mock() @@ -48,8 +48,8 @@ class TestBaseHNVModel(unittest.TestCase): get_resource.assert_called_once_with("/hnv-client-test") self.assertIs(resource, mock.sentinel.resource) - @mock.patch("hnv_client.client._BaseHNVModel.from_raw_data") - @mock.patch("hnv_client.client._BaseHNVModel._get_client") + @mock.patch("hnv.client._BaseHNVModel.from_raw_data") + @mock.patch("hnv.client._BaseHNVModel._get_client") def test_get_all(self, mock_get_client, mock_from_raw_data): mock_from_raw_data.side_effect = range(10) @@ -63,7 +63,7 @@ class TestBaseHNVModel(unittest.TestCase): self.assertEqual(resources, range(10)) @mock.patch("time.sleep") - @mock.patch("hnv_client.client._BaseHNVModel._get_client") + @mock.patch("hnv.client._BaseHNVModel._get_client") def _test_remove(self, mock_get_client, mock_sleep, loop_count, timeout): http_client = mock_get_client.return_value = mock.Mock() @@ -101,9 +101,9 @@ class TestBaseHNVModel(unittest.TestCase): return {"properties": {"provisioningState": provisioning_state}} @mock.patch("time.sleep") - @mock.patch("hnv_client.client._BaseHNVModel.process_raw_data") - @mock.patch("hnv_client.client._BaseHNVModel.dump") - @mock.patch("hnv_client.client._BaseHNVModel._get_client") + @mock.patch("hnv.client._BaseHNVModel.process_raw_data") + @mock.patch("hnv.client._BaseHNVModel.dump") + @mock.patch("hnv.client._BaseHNVModel._get_client") def _test_commit(self, mock_get_client, mock_dump, mock_process, mock_sleep, loop_count, timeout, failed, invalid_response): @@ -174,7 +174,7 @@ class TestClient(unittest.TestCase): self._response = fake_response.FakeResponse() def _test_get_resource(self, model, raw_data): - with test_utils.LogSnatcher("hnv_client.common.model") as logging: + with test_utils.LogSnatcher("hnv.common.model") as logging: model.from_raw_data(raw_data) self.assertEqual(logging.output, []) diff --git a/hnv_client/tests/utils.py b/hnv/tests/utils.py similarity index 97% rename from hnv_client/tests/utils.py rename to hnv/tests/utils.py index c2e39fe..c72257d 100644 --- a/hnv_client/tests/utils.py +++ b/hnv/tests/utils.py @@ -21,7 +21,7 @@ import logging as base_logging from oslo_log import log as oslo_logging -from hnv_client import config as hnv_conf +from hnv import config as hnv_conf CONFIG = hnv_conf.CONFIG @@ -45,7 +45,7 @@ class LogSnatcher(object): The class can be used as following:: - with LogSnatcher('hnv_client.client') as snatcher: + with LogSnatcher('hnv.client') as snatcher: LOG.info("doing stuff") LOG.info("doing stuff %s", 1) LOG.warn("doing other stuff") diff --git a/setup.cfg b/setup.cfg index 1fee727..79622ad 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [metadata] -name = hnv_client +name = hnv version = 0.1.0 summary = Python client for the HNV (Hyper-V Network Virtualization) REST API. description-file = @@ -23,7 +23,7 @@ classifier = [files] packages = - hnv_client + hnv [global] setup-hooks = @@ -31,7 +31,7 @@ setup-hooks = [entry_points] oslo.config.opts = - hnv_client = hnv_client.config.options:get_options + hnv.conf = hnv.config.options:get_options [build_sphinx] all_files = 1 diff --git a/tox.ini b/tox.ini index 8441d18..3a0c44d 100644 --- a/tox.ini +++ b/tox.ini @@ -12,11 +12,11 @@ install_command = pip install -U --force-reinstall {opts} {packages} commands = python setup.py testr --testr-args='{posargs}' [testenv:pep8] -commands = flake8 hnv_client {posargs} +commands = flake8 hnv {posargs} deps = flake8 [testenv:pylint] -commands = pylint hnv_client --rcfile={toxinidir}/.pylintrc {posargs} +commands = pylint hnv --rcfile={toxinidir}/.pylintrc {posargs} deps = pylint [testenv:cover]