New address and new key store/retrieval mthods

set_address: New method for specifying units address for net-splits
             deployments
send_all: Send setting to all peers
retrieve_local: Retrieve key from local db
retrieve_remote: Retrieve key from peers

Fix name of interface.yaml (should not be plural)
Fix tox targetss and drop charm-tools from requirements

Change-Id: I4b0b952c3490cb7c0a877cd827333d69e81ebdab
This commit is contained in:
Liam Young 2016-07-08 13:47:49 +00:00
parent 654f1cfd33
commit 1df295844d
6 changed files with 75 additions and 3 deletions

1
.gitignore vendored
View File

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

4
.gitreview Normal file
View File

@ -0,0 +1,4 @@
[gerrit]
host=review.openstack.org
port=29418
project=openstack/charm-interface-openstack-ha.git

View File

@ -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

View File

@ -1,3 +1,2 @@
flake8>=2.2.4,<=2.4.1
os-testr>=0.4.1
charm-tools

19
tox.ini
View File

@ -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}