commit d5ef76fbd7ecce7d9f3fdf72c33a1431b195d0b3 Author: Andre Ruiz Date: Mon Aug 3 17:13:40 2020 -0300 Initial Cookiecutter Commit. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1f101ef --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +build +layers +.tox +interfaces +.testrepository +.stestr +*__pycache__* +*.pyc diff --git a/.stestr.conf b/.stestr.conf new file mode 100644 index 0000000..5fcccac --- /dev/null +++ b/.stestr.conf @@ -0,0 +1,3 @@ +[DEFAULT] +test_path=./unit_tests +top_dir=./ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..20f335d --- /dev/null +++ b/requirements.txt @@ -0,0 +1,7 @@ +# This file is managed centrally. If you find the need to modify this as a +# one-off, please don't. Intead, consult #openstack-charms and ask about +# requirements management in charms via bot-control. Thank you. +# +# Build requirements +charm-tools>=2.4.4 +simplejson diff --git a/src/README.md b/src/README.md new file mode 100644 index 0000000..d777a98 --- /dev/null +++ b/src/README.md @@ -0,0 +1,19 @@ +lvm Storage Backend for Cinder +------------------------------- + +Overview +======== + +This charm provides a lvm storage backend for use with the Cinder +charm. + +To use: + + juju deploy cinder + juju deploy cinder-lvm + juju add-relation cinder-lvm cinder + +Configuration +============= + +See config.yaml for details of configuration options. diff --git a/src/config.yaml b/src/config.yaml new file mode 100644 index 0000000..a54da99 --- /dev/null +++ b/src/config.yaml @@ -0,0 +1 @@ +options: diff --git a/src/layer.yaml b/src/layer.yaml new file mode 100644 index 0000000..2ff600a --- /dev/null +++ b/src/layer.yaml @@ -0,0 +1,12 @@ +includes: ['layer:openstack', 'interface:cinder-backend'] +config: + deletes: + - debug + - verbose + - use-syslog + - use-internal-endpoints + - ssl_ca +options: + basic: + use_venv: True +repo: https://github.com/openstack-charmers/cinder-storage-backend-template diff --git a/src/lib/charm/openstack/cinder_lvm.py b/src/lib/charm/openstack/cinder_lvm.py new file mode 100644 index 0000000..83e5e04 --- /dev/null +++ b/src/lib/charm/openstack/cinder_lvm.py @@ -0,0 +1,32 @@ +import charms_openstack.charm +import charmhelpers.core.hookenv as ch_hookenv # noqa + +charms_openstack.charm.use_defaults('charm.default-select-release') + + +class CinderlvmCharm( + charms_openstack.charm.CinderStoragePluginCharm): + + name = 'cinder_lvm' + version_package = 'cinder-volume' + release = 'ocata' + packages = [version_package] + stateless = True + # Specify any config that the user *must* set. + mandatory_config = [] + + def cinder_configuration(self): + volume_driver = '' + driver_options = [ + ('volume_driver', volume_driver), + # Add config options that needs setting on cinder.conf + ] + return driver_options + + +class CinderlvmCharmRocky(CinderlvmCharm): + + # Rocky needs py3 packages. + release = 'rocky' + version_package = 'cinder-volume' + packages = [version_package] diff --git a/src/metadata.yaml b/src/metadata.yaml new file mode 100644 index 0000000..4b2bf1d --- /dev/null +++ b/src/metadata.yaml @@ -0,0 +1,24 @@ +name: cinder-lvm +summary: lvm integration for OpenStack Block Storage +maintainer: OpenStack Charmers +description: | + Cinder is the block storage service for the Openstack project. + . + This charm provides a lvm backend for Cinder +tags: + - openstack + - storage + - file-servers + - misc +series: + - xenial + - bionic +subordinate: true +provides: + storage-backend: + interface: cinder-backend + scope: container +requires: + juju-info: + interface: juju-info + scope: container diff --git a/src/reactive/cinder_lvm_handlers.py b/src/reactive/cinder_lvm_handlers.py new file mode 100644 index 0000000..c503fa2 --- /dev/null +++ b/src/reactive/cinder_lvm_handlers.py @@ -0,0 +1,35 @@ +# Copyright 2019 +# +# 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 charms_openstack.charm +import charms.reactive + +# This charm's library contains all of the handler code associated with +# this charm -- we will use the auto-discovery feature of charms.openstack +# to get the definitions for the charm. +import charms_openstack.bus +charms_openstack.bus.discover() + +charms_openstack.charm.use_defaults( + 'charm.installed', + 'update-status', + 'upgrade-charm', + 'storage-backend.connected', +) + + +@charms.reactive.when('config.changed.driver-source') +def reinstall(): + with charms_openstack.charm.provide_charm_instance() as charm: + charm.install() diff --git a/src/test-requirements.txt b/src/test-requirements.txt new file mode 100644 index 0000000..f2912ba --- /dev/null +++ b/src/test-requirements.txt @@ -0,0 +1,3 @@ +# zaza +git+https://github.com/openstack-charmers/zaza.git#egg=zaza +git+https://github.com/openstack-charmers/zaza-openstack-tests.git#egg=zaza.openstack diff --git a/src/tests/bundles/xenial-ocata.yaml b/src/tests/bundles/xenial-ocata.yaml new file mode 100644 index 0000000..81fec23 --- /dev/null +++ b/src/tests/bundles/xenial-ocata.yaml @@ -0,0 +1,50 @@ +series: xenial +comment: +- 'machines section to decide order of deployment. database sooner = faster' +machines: + '0': + constraints: mem=3072M + '1': + '2': + '3': +relations: +- - keystone:shared-db + - mysql:shared-db +- - cinder:shared-db + - mysql:shared-db +- - cinder:identity-service + - keystone:identity-service +- - cinder:amqp + - rabbitmq-server:amqp +- - cinder:storage-backend + - cinder-lvm:storage-backend +applications: + mysql: + charm: cs:~openstack-charmers-next/percona-cluster + num_units: 1 + to: + - '0' + keystone: + charm: cs:~openstack-charmers-next/keystone + num_units: 1 + options: + openstack-origin: cloud:xenial-ocata + to: + - '1' + cinder: + charm: cs:~openstack-charmers-next/cinder + num_units: 1 + options: + openstack-origin: cloud:xenial-ocata + to: + - '2' + cinder-lvm: + series: xenial + charm: cinder-lvm + options: +# Add config options here + rabbitmq-server: + charm: cs:~openstack-charmers-next/rabbitmq-server + num_units: 1 + to: + - '3' diff --git a/src/tests/tests.yaml b/src/tests/tests.yaml new file mode 100644 index 0000000..edc94f8 --- /dev/null +++ b/src/tests/tests.yaml @@ -0,0 +1,9 @@ +charm_name: cinder-lvm +tests: + - tests.tests_cinder_lvm.CinderlvmTest +configure: + - zaza.openstack.charm_tests.keystone.setup.add_demo_user +gate_bundles: + - xenial-ocata +smoke_bundles: + - xenial-ocata diff --git a/src/tests/tests_cinder_lvm.py b/src/tests/tests_cinder_lvm.py new file mode 100644 index 0000000..171797e --- /dev/null +++ b/src/tests/tests_cinder_lvm.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python3 + +# Copyright 2019 Canonical Ltd. +# +# 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. + +"""Encapsulate cinder-lvm testing.""" + +import logging +import uuid + +import zaza.model +import zaza.openstack.charm_tests.test_utils as test_utils +import zaza.openstack.utilities.openstack as openstack_utils + + +class CinderlvmTest(test_utils.OpenStackBaseTest): + """Encapsulate lvm tests.""" + + @classmethod + def setUpClass(cls): + """Run class setup for running tests.""" + super(CinderlvmTest, cls).setUpClass() + cls.keystone_session = openstack_utils.get_overcloud_keystone_session() + cls.model_name = zaza.model.get_juju_model() + cls.cinder_client = openstack_utils.get_cinder_session_client( + cls.keystone_session) + + def test_cinder_config(self): + logging.info('lvm') + expected_contents = { + 'cinder-lvm': { + 'iscsi_helper': ['tgtadm'], + 'volume_dd_blocksize': ['512']}} + + zaza.model.run_on_leader( + 'cinder', + 'sudo cp /etc/cinder/cinder.conf /tmp/', + model_name=self.model_name) + zaza.model.block_until_oslo_config_entries_match( + 'cinder', + '/tmp/cinder.conf', + expected_contents, + model_name=self.model_name, + timeout=2) + + def test_create_volume(self): + test_vol_name = "zaza{}".format(uuid.uuid1().fields[0]) + vol_new = self.cinder_client.volumes.create( + name=test_vol_name, + size=2) + openstack_utils.resource_reaches_status( + self.cinder_client.volumes, + vol_new.id, + expected_status='available') + test_vol = self.cinder_client.volumes.find(name=test_vol_name) + self.assertEqual( + getattr(test_vol, 'os-vol-host-attr:host').split('#')[0], + 'cinder@cinder-lvm') + self.cinder_client.volumes.delete(vol_new) diff --git a/src/tox.ini b/src/tox.ini new file mode 100644 index 0000000..ce45106 --- /dev/null +++ b/src/tox.ini @@ -0,0 +1,35 @@ +[tox] +envlist = pep8 +skipsdist = True + +[testenv] +setenv = VIRTUAL_ENV={envdir} + PYTHONHASHSEED=0 +whitelist_externals = juju +passenv = HOME TERM CS_API_* OS_* AMULET_* +deps = -r{toxinidir}/test-requirements.txt +install_command = + pip install {opts} {packages} + +[testenv:pep8] +basepython = python3 +deps=charm-tools +commands = charm-proof + +[testenv:func-noop] +basepython = python3 +commands = + true + +[testenv:func] +basepython = python3 +commands = + functest-run-suite --keep-model + +[testenv:func-smoke] +basepython = python3 +commands = + functest-run-suite --keep-model --smoke + +[testenv:venv] +commands = {posargs} diff --git a/src/wheelhouse.txt b/src/wheelhouse.txt new file mode 100644 index 0000000..ebd9154 --- /dev/null +++ b/src/wheelhouse.txt @@ -0,0 +1,2 @@ +#layer-basic uses wheelhouse to install python dependencies +psutil \ No newline at end of file diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..368dbf2 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,7 @@ +# Lint and unit test requirements +flake8 +os-testr>=0.4.1 +charms.reactive +mock>=1.2 +coverage>=3.6 +git+https://github.com/openstack/charms.openstack.git#egg=charms-openstack diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..8900d83 --- /dev/null +++ b/tox.ini @@ -0,0 +1,61 @@ +# Source charm: ./tox.ini +# This file is managed centrally by release-tools and should not be modified +# within individual charm repos. +[tox] +skipsdist = True +envlist = pep8,py34,py35,py36 +skip_missing_interpreters = True + +[testenv] +setenv = VIRTUAL_ENV={envdir} + PYTHONHASHSEED=0 + TERM=linux + LAYER_PATH={toxinidir}/layers + INTERFACE_PATH={toxinidir}/interfaces + JUJU_REPOSITORY={toxinidir}/build +passenv = http_proxy https_proxy +install_command = + pip install {opts} {packages} +deps = + -r{toxinidir}/requirements.txt + +[testenv:build] +basepython = python3 +commands = + charm-build --log-level DEBUG -o {toxinidir}/build src {posargs} + +[testenv:py27] +basepython = python2.7 +# Reactive source charms are Python3-only, but a py27 unit test target +# is required by OpenStack Governance. Remove this shim as soon as +# permitted. https://governance.openstack.org/tc/reference/cti/python_cti.html +whitelist_externals = true +commands = true + +[testenv:py34] +basepython = python3.4 +deps = -r{toxinidir}/test-requirements.txt +commands = stestr run {posargs} + +[testenv:py35] +basepython = python3.5 +deps = -r{toxinidir}/test-requirements.txt +commands = stestr run {posargs} + +[testenv:py36] +basepython = python3.6 +deps = -r{toxinidir}/test-requirements.txt +commands = stestr run {posargs} + +[testenv:pep8] +basepython = python3 +deps = -r{toxinidir}/test-requirements.txt +commands = flake8 {posargs} src unit_tests + +[testenv:venv] +basepython = python3 +commands = {posargs} + +[flake8] +# E402 ignore necessary for path append before sys module import in actions +ignore = E402 diff --git a/unit_tests/__init__.py b/unit_tests/__init__.py new file mode 100644 index 0000000..3a5e9a3 --- /dev/null +++ b/unit_tests/__init__.py @@ -0,0 +1,22 @@ +# Copyright 2016 Canonical Ltd +# +# 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 sys + +sys.path.append('src') +sys.path.append('src/lib') + +# Mock out charmhelpers so that we can test without it. +import charms_openstack.test_mocks # noqa +charms_openstack.test_mocks.mock_charmhelpers() diff --git a/unit_tests/test_lib_charm_openstack_cinder_lvm.py b/unit_tests/test_lib_charm_openstack_cinder_lvm.py new file mode 100644 index 0000000..a0379fd --- /dev/null +++ b/unit_tests/test_lib_charm_openstack_cinder_lvm.py @@ -0,0 +1,49 @@ +# Copyright 2016 Canonical Ltd +# +# 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 __future__ import absolute_import +from __future__ import print_function + +import charmhelpers + +import charm.openstack.cinder_lvm as cinder_lvm + +import charms_openstack.test_utils as test_utils + + +class TestCinderlvmCharm(test_utils.PatchHelper): + + def _patch_config_and_charm(self, config): + self.patch_object(charmhelpers.core.hookenv, 'config') + + def cf(key=None): + if key is not None: + return config[key] + return config + + self.config.side_effect = cf + c = cinder_lvm.CinderlvmCharm() + return c + + def test_cinder_base(self): + charm = self._patch_config_and_charm({}) + self.assertEqual(charm.name, 'cinder_lvm') + self.assertEqual(charm.version_package, 'cinder-volume') + self.assertEqual(charm.packages, ['cinder-volume']) + + def test_cinder_configuration(self): + charm = self._patch_config_and_charm({'a': 'b'}) + config = charm.cinder_configuration() # noqa + # Add check here that configuration is as expected. + # self.assertEqual(config, {})