More tidy up

This commit is contained in:
Liam Young 2020-11-13 11:15:26 +00:00
parent 32832363d4
commit e4f0ceef05
8 changed files with 77 additions and 174 deletions

25
LICENSE
View File

@ -175,3 +175,28 @@
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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.

View File

@ -1,16 +0,0 @@
Format: http://dep.debian.net/deps/dep5/
Files: *
Copyright: Copyright 2015, Canonical Ltd., All Rights Reserved.
License: Apache License 2.0
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.

53
perf.py
View File

@ -1,53 +0,0 @@
import sys
import subprocess
import threading
class Iperf():
"""
Install and start a server automatically
"""
try:
if not nextline:
mtu = None
except NameError:
mtu = None
# The following is a mess - since I'm installing iperf3 in the function
# Surely there is another easier way to get this into the charm?
def __init__(self):
#try:
# subprocess.check_call(['pgrep', 'iperf'], stderr=subprocess.STDOUT)
# if a:
thread = threading.Thread(target=self.start_server, args=())
thread.start()
#except:
# pass
#hookenv.log(sys.exc_info()[0], 'INFO')
def start_server(self):
process = subprocess.Popen(['iperf', '-s', '-m'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while True:
nextline = process.stdout.readline()
nextline = nextline.decode("utf-8")
if nextline == '' and process.poll() is not None:
break
if "bits" in nextline:
self.speed = nextline.rsplit(' ', 2)[1]
sys.stdout.write(self.speed)
sys.stdout.write("\n")
if "MTU" in nextline:
self.mtu = nextline.rsplit(' ', 4)[1]
sys.stdout.write(self.mtu)
sys.stdout.flush()
#output = process.communicate()[0]
#exitCode = process.returncode
#
#output = exitCode
#if (exitCode == 0):
# pass
#elif exitCode:
# raise Exception(command, exitCode, output)
perf = Iperf()
#print (perf.mtu)

View File

@ -175,3 +175,28 @@
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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.

View File

@ -1,4 +1,16 @@
#!/usr/bin/env python
# Copyright 2020 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 os
import subprocess

View File

@ -1,3 +1,17 @@
# Copyright 2020 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.
# pylint: disable=unused-argument
from charms.reactive import when, when_not, set_state, remove_state
from charmhelpers.core import hookenv

View File

@ -1,21 +0,0 @@
#!/usr/bin/env python3
import unittest
import amulet
class TestDeploy(unittest.TestCase):
"""
Trivial deployment test for Magpie
"""
def test_deploy(self):
self.d = amulet.Deployment(series='xenial')
self.d.add('magpie', charm='~admcleod/magpie')
self.d.setup(timeout=900)
self.d.sentry.wait_for_messages({'magpie': 'Waiting for peers...'},
timeout=3600)
if __name__ == '__main__':
unittest.main()

View File

@ -1,83 +0,0 @@
#!/usr/bin/env python3
import re
import unittest
import amulet
class TestDeploy(unittest.TestCase):
"""
Deploy 2 peers and make sure their status messages contain "or" or "failed"
This does not test the substrate - only that the charms deploy and relate.
"""
@classmethod
def setUpClass(cls):
cls.d = amulet.Deployment(series='xenial')
cls.d.add('magpie', charm='~admcleod/magpie', units=2)
cls.d.setup(timeout=900)
cls.magpie_0 = cls.d.sentry['magpie'][0]
cls.magpie_1 = cls.d.sentry['magpie'][1]
def test_deploy(self):
self.d.sentry.wait_for_messages({'magpie': re.compile('ok|failed')},
timeout=60)
# following test is commented out until this bug is resolved;
# https://bugs.launchpad.net/juju/+bug/1623480
# def test_check_local_hostname(self):
# self.d.sentry.wait_for_messages({'magpie': {re.compile('.*hostname
# ok.*'}}, timeout=60)
def test_break_dns_single(self):
print('Test break dns single...')
"""
Break DNS on one unit, make sure DNS check fails, fix DNS, toggle
back
"""
self.d.sentry.wait_for_messages({'magpie': 'icmp ok, dns ok'},
timeout=60)
self.magpie_0.run("sudo mv /etc/resolv.conf /etc/resolv.conf.bak")
self.magpie_0.run("hooks/update-status")
self.d.sentry.wait_for_messages({'magpie':
{re.compile('.*dns failed*')}},
timeout=60)
self.magpie_0.run("sudo mv /etc/resolv.conf.bak /etc/resolv.conf")
self.magpie_0.run("hooks/update-status")
self.d.sentry.wait_for_messages({'magpie': 'icmp ok, dns ok'},
timeout=60)
def test_break_dns_all(self):
print('Test break dns all...')
"""
Set DNS with action to 255.255.255.255 - All units should fail DNS.
"""
self.d.configure('magpie', {'dns_server': '255.255.255.255'})
self.magpie_0.run("hooks/update-status")
self.magpie_1.run("hooks/update-status")
self.d.sentry.wait_for_messages({'magpie':
re.compile('icmp ok,.*dns failed.*')})
self.d.configure('magpie', {'dns_server': ''})
self.magpie_0.run("hooks/update-status")
self.magpie_1.run("hooks/update-status")
self.d.sentry.wait_for_messages({'magpie': 'icmp ok, dns ok'})
def test_break_ping_single(self):
print('Test break ping single')
"""
Take primary interface down and make sure ICMP fails.
"""
stoprestart = "(sudo service networking stop; sleep 60; service \
networking start) & "
self.magpie_1.run(stoprestart)
self.magpie_1.run("hooks/update-status")
self.d.sentry.wait_for_messages({'magpie':
{re.compile('icmp failed.*')}},
timeout=120)
self.magpie_1.run("hooks/update-status")
self.d.sentry.wait_for_messages({'magpie': {re.compile('icmp ok.*')}},
timeout=120)
if __name__ == '__main__':
unittest.main()