RootConf 2016
Talk about testing issues we had for the releasing regular cloud builds
Places where we have to test
Show them the actual test case, like checking if no service is failed or not during bootup.
systemctl --all --failed
Talk about open source projects, all those small projects we have laying around in our servers/laptops.
Original work from https://xkcd.com/386/
Now remember about supporting this for 10 years. Do you remember the code you wrote 6 months back?
{ "name": "default", "type": "vm", "image": "/home/Fedora-Cloud-Base-20141203-21.x86_64.qcow2", "ram": 1024, "user": "fedora", }
Show the Python code to read a json file for configuration. Then the same for ini/cfg files, and then letting people to think about how to do the same in bash. One example project is https://github.com/dominictarr/JSON.sh/blob/master/JSON.sh
import json json.load(...) # For file like objects json.loads() # From string
Show one example test case, talk about how is enabled a new group of contributors to come in and write more test cases than ever.
def test_services(self): "No service should fail in the startup." out, err, eid = system('systemctl --all --failed') out = out.decode('utf-8') self.assertIn('0 loaded units listed', out)
About the default modules available on a Python system. It will be there on every linux server, means you can use your code, without adding any new dependency. Talk about ksc project, which ran from python2.2 to Python2.7.
Show Error handling in Python, a few different examples about how detailed it can be.
try: obj.connect(...) except socket.timeout: # We have a timeout in the command status = False timeout_issue = True break except paramiko.ssh_exception.SSHException: status = False ssh_issue = True
import pdb;pdb.set_strace()
We may have to retry the same function for any error, let us use python decorators to do the same. We want logging too.
class TestDockerInstalled(unittest.TestCase): def test_run(self): out, err, eid = system('rpm -q docker') out = out.decode('utf-8') self.assertFalse('not installed' in out, out)
@unittest.skipUnless(if_atomic(), "It's not an Atomic image") class TestDockerInstalled(unittest.TestCase): def test_run(self): out, err, eid = system('rpm -q docker') out = out.decode('utf-8') self.assertFalse('not installed' in out, out)
def check_double(num): if num > 10 and num % 2 == 0: return num * 2 else: return -1 numbers = [56, 76, 30, 9, 23] map(check_double, numbers) [112, 152, 60, -1, -1]
def my_decorator(func): def wrapper(*args, **kwargs): print("Before call") result = func(*args, **kwargs) print("After call") return result return wrapper
@my_decorator def hello(): print "Hello" hello() Before call Hello After call
Let us see how do we use this to create a class for managing Vagrant instnaces.
cmd = 'vagrant box add {0} --name {1}'.format(image_url, name) out, err, retcode = system(cmd) # Now check for error, I will skip this. if retcode != 0: print("Error while trying to add the box.") print(err) self.failed = True return print(out) print("Up the vagrant") # Let us up the vagrant cmd = 'vagrant up --provider {0}'.format(self.provider) out, err, retcode = system(cmd)
How do we add a function to take care of the same.
For happy users we need to get the same in AWS
30 providers
cffi, raw c extension by hand
Demo a simple fabric code to run on many servers.
from fabric.api import run def host_type(): run('uname -s')
Who all can identify this logo? Who all uses Ansible here?
Fedora Ansible repo
@kushaldas
Space | Forward |
---|---|
Left, Down, Page Down | Next slide |
Right, Up, Page Up | Previous slide |
P | Open presenter console |
H | Toggle this help |