General fixes and tests

This commit is contained in:
Liam Young 2020-02-26 14:21:19 +00:00
parent 03e1952419
commit 00ee31a214
11 changed files with 69 additions and 126 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
lib
.tox

View File

@ -11,6 +11,10 @@ from ops.framework import (
StoredState,
)
from ops.main import main
from ops.model import (
ActiveStatus,
WaitingStatus,
)
from charmhelpers.fetch import (
apt_install,
apt_update,
@ -31,7 +35,9 @@ class CephISCSIGatewayCharm(CharmBase):
def __init__(self, framework, key):
super().__init__(framework, key)
self.state.set_default(is_started=False)
self.framework.observe(self.on.install, self)
self.framework.observe(self.on.update_status, self)
self.framework.observe(self.on.ceph_client_relation_joined, self)
self.ceph_client = interface_ceph_client.CephClientRequires(
self,
@ -42,6 +48,12 @@ class CephISCSIGatewayCharm(CharmBase):
apt_update(fatal=True)
apt_install(self.PACKAGES, fatal=True)
def on_update_status(self, event):
if self.state.is_started:
self.model.unit.status = ActiveStatus('Unit is ready')
else:
self.model.unit.status = WaitingStatus('not ready for reasons')
def on_ceph_client_relation_joined(self, event):
self.ceph_client.create_replicated_pool('rbd')
self.ceph_client.request_ceph_permissions(
@ -77,6 +89,8 @@ class CephISCSIGatewayCharm(CharmBase):
config_file,
ceph_context)
render_configs()
self.state.is_started = True
self.model.unit.status = ActiveStatus('Unit is ready')
if __name__ == '__main__':

View File

@ -1,13 +1,13 @@
# 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.
#
# Lint and unit test requirements
charm-tools>=2.4.4
coverage>=3.6
mock>=1.2
flake8>=2.2.4,<=2.4.1
stestr>=2.2.0
requests>=2.18.4
charms.reactive
mock>=1.2
nose>=1.3.7
coverage>=3.6
git+https://github.com/openstack/charms.openstack.git#egg=charms.openstack
git+https://github.com/gnuoy/zaza.git@force-focal#egg=zaza
git+https://github.com/gnuoy/zaza-openstack-tests.git@ceph-iscsi-tests#egg=zaza.openstack
pytz # workaround for 14.04 pip/tox
pyudev # for ceph-* charm unit tests (not mocked?)

View File

@ -1,7 +0,0 @@
#!/bin/bash
client="ubuntu/0"
juju run --unit $client "apt install --yes open-iscsi multipath-tools"
juju run --unit $client "systemctl start iscsi"
juju run --unit $client "systemctl start iscsid"

View File

@ -1,26 +0,0 @@
#!/bin/bash -x
gw1="ceph-iscsi/0"
gw2="ceph-iscsi/1"
gw1_hostname=$(juju run --unit $gw1 "hostname -f")
gw2_hostname=$(juju run --unit $gw2 "hostname -f")
gw1_ip=$(juju status $gw1 --format=oneline | awk '{print $3}' | tr -d \\n )
gw2_ip=$(juju status $gw2 --format=oneline | awk '{print $3}' | tr -d \\n )
client_initiatorname=$(juju run --unit ubuntu/0 "grep -E '^InitiatorName' /etc/iscsi/initiatorname.iscsi")
client_initiatorname=$(echo $client_initiatorname | awk 'BEGIN {FS="="} {print $2}')
echo "!$gw1_hostname!"
echo "!$gw2_hostname!"
echo "!$gw1_ip!"
echo "!$gw2_ip!"
echo "!$client_initiatorname!"
gw_iqn="iqn.2003-01.com.canonical.iscsi-gw:iscsi-igw"
juju run --unit $gw1 "gwcli /iscsi-targets/ create $gw_iqn"
juju run --unit $gw1 "gwcli /iscsi-targets/${gw_iqn}/gateways create $gw1_hostname $gw1_ip skipchecks=true"
juju run --unit $gw1 "gwcli /iscsi-targets/${gw_iqn}/gateways create $gw2_hostname $gw2_ip skipchecks=true"
juju run --unit $gw1 "gwcli /disks create pool=rbd image=disk_1 size=1G"
juju run --unit $gw1 "gwcli /iscsi-targets/${gw_iqn}/hosts create ${client_initiatorname}"
juju run --unit $gw1 "gwcli /iscsi-targets/${gw_iqn}/hosts/${client_initiatorname} auth username=myiscsiusername password=myiscsipassword"
juju run --unit $gw1 "gwcli /iscsi-targets/${gw_iqn}/hosts/${client_initiatorname} disk add rbd/disk_1"

View File

@ -1,18 +0,0 @@
#!/bin/bash
client="ubuntu/0"
gw1="ceph-iscsi/0"
gw1_ip=$(juju status $gw1 --format=oneline | awk '{print $3}' | tr -d \\n )
juju run --unit $client "iscsiadm -m discovery -t st -p $gw1_ip"
target_name="iqn.2003-01.com.canonical.iscsi-gw:iscsi-igw"
juju run --unit $client "iscsiadm --mode node --targetname ${target_name} --op=update --name node.session.auth.authmethod --value=CHAP"
juju run --unit $client "iscsiadm --mode node --targetname ${target_name} --op=update --name node.session.auth.username --value=myiscsiusername"
juju run --unit $client "iscsiadm --mode node --targetname ${target_name} --op=update --name node.session.auth.password --value=myiscsipassword"
juju run --unit $client "iscsiadm --mode node --targetname ${target_name} --login"
sleep 5
juju ssh ubuntu/0 "ls -l /dev/dm-0"

View File

@ -4,7 +4,7 @@ applications:
charm: cs:ubuntu
num_units: 1
ceph-iscsi:
charm: ../
charm: ../../
series: focal
num_units: 2
ceph-osd:

View File

@ -1 +0,0 @@
juju deploy --force ./focal.yaml

9
tests/tests.yaml Normal file
View File

@ -0,0 +1,9 @@
charm_name: ceph-iscsi
gate_bundles:
- focal
smoke_bundles:
- focal
configure:
- zaza.openstack.charm_tests.ceph.iscsi.setup.basic_guest_setup
tests:
- zaza.openstack.charm_tests.ceph.iscsi.tests.CephISCSIGatewayTest

13
todo.txt Normal file
View File

@ -0,0 +1,13 @@
Confirm zaza tests are working
Remove hardcoded ceph pool name and expose as a config option
Write spec
Fix workload status so it reports missing relations
Implement pause/resume
Add iscsi target create action
Add series upgrade
Write README
Move to openstack-charmers
Refactor ceph broker code in charm helpers
Rewrite ceph-client interface to stop using any relation* commands via charmhelpers
implement source config option
Proper Update Status

90
tox.ini
View File

@ -1,12 +1,12 @@
# Source charm: ./tox.ini
# Source charm (with zaza): ./src/tox.ini
# This file is managed centrally by release-tools and should not be modified
# within individual charm repos. See the 'global' dir contents for available
# choices of tox.ini for OpenStack Charms:
# https://github.com/openstack-charmers/release-tools
[tox]
envlist = pep8
skipsdist = True
envlist = pep8,py3
# NOTE: Avoid build/test env pollution by not enabling sitepackages.
sitepackages = False
# NOTE: Avoid false positives by not skipping missing interpreters.
@ -15,78 +15,36 @@ skip_missing_interpreters = False
[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 INTERFACE_PATH LAYER_PATH JUJU_REPOSITORY
whitelist_externals = juju
passenv = HOME TERM CS_* OS_* TEST_*
deps = -r{toxinidir}/test-requirements.txt
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:py3]
basepython = python3
deps = -r{toxinidir}/test-requirements.txt
commands = stestr run --slowest {posargs}
[testenv:py35]
basepython = python3.5
deps = -r{toxinidir}/test-requirements.txt
commands = stestr run --slowest {posargs}
[testenv:py36]
basepython = python3.6
deps = -r{toxinidir}/test-requirements.txt
commands = stestr run --slowest {posargs}
[testenv:py37]
basepython = python3.7
deps = -r{toxinidir}/test-requirements.txt
commands = stestr run --slowest {posargs}
[testenv:pep8]
basepython = python3
deps = -r{toxinidir}/test-requirements.txt
commands = flake8 {posargs} src unit_tests
deps=charm-tools
commands = charm-proof
[testenv:cover]
# Technique based heavily upon
# https://github.com/openstack/nova/blob/master/tox.ini
[testenv:func-noop]
basepython = python3
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
setenv =
{[testenv]setenv}
PYTHON=coverage run
commands =
coverage erase
stestr run --slowest {posargs}
coverage combine
coverage html -d cover
coverage xml -o cover/coverage.xml
coverage report
functest-run-suite --help
[coverage:run]
branch = True
concurrency = multiprocessing
parallel = True
source =
.
omit =
.tox/*
*/charmhelpers/*
unit_tests/*
[testenv:func]
basepython = python3
commands =
functest-run-suite --keep-model
[testenv:func-smoke]
basepython = python3
commands =
functest-run-suite --keep-model --smoke
[testenv:func-target]
basepython = python3
commands =
functest-run-suite --keep-model --bundle {posargs}
[testenv:venv]
basepython = python3
commands = {posargs}
[flake8]
# E402 ignore necessary for path append before sys module import in actions
ignore = E402,W504
commands = {posargs}