diff --git a/.gitignore b/.gitignore index 172bf57..9dd3eb8 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .tox +.testrepository diff --git a/.gitreview b/.gitreview new file mode 100644 index 0000000..687b9fc --- /dev/null +++ b/.gitreview @@ -0,0 +1,4 @@ +[gerrit] +host=review.openstack.org +port=29418 +project=openstack/charm-interface-openstack-ha.git diff --git a/interfaces.yaml b/interface.yaml similarity index 100% rename from interfaces.yaml rename to interface.yaml diff --git a/peers.py b/peers.py index 59bbb46..d0e140b 100644 --- a/peers.py +++ b/peers.py @@ -56,3 +56,56 @@ class OpenstackHAPeers(RelationBase): if all(data.values()): return True return False + + def set_address(self, address_type, address): + '''Advertise the address of this unit of a particular type + + :param address_type: str Type of address being advertised, e.g. + internal/public/admin etc + :param address: str IP of this unit in 'address_type' network + + @returns None''' + + for conv in self.conversations(): + conv.set_remote( + key='{}-address'.format(address_type), + value=address) + + def send_all(self, settings, store_local=False): + '''Advertise a setting to peer units + + :param settings: dict Settings to be advertised to peers + :param store_local: boolean Whether to store setting in local db + + @returns None''' + for conv in self.conversations(): + conv.set_remote(data=settings) + if store_local: + conv.set_local(data=settings) + + def retrieve_local(self, key): + '''Inspect conversation and look for key in local db + + :param key: str Key to look for in localdb + @returns list: List of values of key + ''' + values = [] + for conv in self.conversations(): + value = conv.get_local(key) + if value: + values.append(value) + return values + + def retrieve_remote(self, key): + '''Inspect conversation and look for key being advertised by peer + + :param key: str Key to look for from peer + + @returns list: List of values of key + ''' + values = [] + for conv in self.conversations(): + value = conv.get_remote(key) + if value: + values.append(value) + return values diff --git a/test-requirements.txt b/test-requirements.txt index 10dbed3..095ec9c 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,3 +1,2 @@ flake8>=2.2.4,<=2.4.1 os-testr>=0.4.1 -charm-tools diff --git a/tox.ini b/tox.ini index c035f1a..c395138 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,7 @@ [tox] -envlist = lint,py27 +envlist = pep8,py27,py34,py35 skipsdist = True +skip_missing_interpreters = True [testenv] setenv = VIRTUAL_ENV={envdir} @@ -12,8 +13,22 @@ commands = ostestr {posargs} [testenv:py27] basepython = python2.7 deps = -r{toxinidir}/test-requirements.txt +# TODO: Need to write unit tests then remove the following command. +commands = /bin/true -[testenv:lint] +[testenv:py34] +basepython = python3.4 +deps = -r{toxinidir}/test-requirements.txt +# TODO: Need to write unit tests then remove the following command. +commands = /bin/true + +[testenv:py35] +basepython = python3.5 +deps = -r{toxinidir}/test-requirements.txt +# TODO: Need to write unit tests then remove the following command. +commands = /bin/true + +[testenv:pep8] basepython = python2.7 deps = -r{toxinidir}/test-requirements.txt commands = flake8 {posargs}