Merge lp:~mskalka/juju-ci-tools/better-internet-test into lp:juju-ci-tools

Proposed by Michael Skalka
Status: Merged
Merged at revision: 1943
Proposed branch: lp:~mskalka/juju-ci-tools/better-internet-test
Merge into: lp:juju-ci-tools
Diff against target: 94 lines (+31/-20)
2 files modified
assess_network_health.py (+9/-9)
tests/test_assess_network_health.py (+22/-11)
To merge this branch: bzr merge lp:~mskalka/juju-ci-tools/better-internet-test
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+320541@code.launchpad.net

Description of the change

Changes the behavior of the internet test to work with containers.

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

ty

review: Approve (code)
1943. By Michael Skalka

changed internet test behavior to work with containers

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'assess_network_health.py'
2--- assess_network_health.py 2017-03-21 16:28:36 +0000
3+++ assess_network_health.py 2017-03-21 18:36:35 +0000
4@@ -242,19 +242,19 @@
5 "machine: {}".format(unit[0]))
6 results[unit[0]] = False
7 try:
8- routes = self.ssh(client, unit[0], 'ip route show')
9+ routes = client.run(['ip route show'], machines=[unit[0]])
10 except subprocess.CalledProcessError:
11 log.error('Could not connect to address for unit: {0}, '
12 'unable to find default route.'.format(unit[0]))
13 continue
14- default_route = re.search(r'^default\s+via\s+([\d\.]+)\s+', routes,
15- re.MULTILINE)
16+ default_route = re.search(r'(default via )+([\d\.]+)\s+',
17+ json.dumps(routes[0]))
18 if default_route:
19- rc = client.juju('ssh', ('--proxy', unit[0],
20- 'ping -c1 -q ' +
21- default_route.group(1)),
22- check=False)
23- if rc != 0:
24+ rc = client.run(
25+ ['ping -c1 -q {}'.format(default_route.group(2))],
26+ machines=[unit[0]])
27+ sucess = re.search(r'(1 received)', json.dumps(rc[0]))
28+ if not sucess:
29 log.error('{} unable to ping default route'.format(unit))
30 continue
31 else:
32@@ -436,7 +436,7 @@
33 for service, unit_res in service_result.items():
34 if False in unit_res.values():
35 failed = [u for u, r in unit_res.items() if r is False]
36- error = ('NH-Unit {0} failed to contact '
37+ error = ('Unit {0} failed to contact '
38 'targets(s): {1}'.format(nh_source, failed))
39 error_string.append(error)
40 for unit, res in internet.items():
41
42=== modified file 'tests/test_assess_network_health.py'
43--- tests/test_assess_network_health.py 2017-03-20 17:50:50 +0000
44+++ tests/test_assess_network_health.py 2017-03-21 18:36:35 +0000
45@@ -263,27 +263,38 @@
46
47 self.assertEqual(expected, out)
48
49- def test_internet_connection(self):
50+ def test_internet_connection_with_pass(self):
51 args = parse_args([])
52 net_health = AssessNetworkHealth(args)
53 client = fake_juju_client()
54 client.bootstrap()
55- default = dedent("""
56- default via 1.1.1.1
57- default via 1.1.1.1
58- """)
59+ default = ["default via 1.1.1.1 1 received"]
60+
61 now = datetime.now() + timedelta(days=1)
62 with patch('utility.until_timeout.now', return_value=now):
63 with patch.object(client, 'get_status', return_value=status):
64- with patch('subprocess.check_output',
65- return_value=None):
66- with patch('assess_network_health.AssessNetworkHealth.ssh',
67- return_value=default):
68- with patch.object(client, 'juju', return_value=0):
69- out = net_health.internet_connection(client)
70+ with patch('subprocess.check_output', return_value=None):
71+ with patch.object(client, 'run', return_value=default):
72+ out = net_health.internet_connection(client)
73 expected = {'1': True, '0': True}
74 self.assertEqual(expected, out)
75
76+ def test_internet_connection_with_fail(self):
77+ args = parse_args([])
78+ net_health = AssessNetworkHealth(args)
79+ client = fake_juju_client()
80+ client.bootstrap()
81+ default = ["default via 1.1.1.1 0 received"]
82+
83+ now = datetime.now() + timedelta(days=1)
84+ with patch('utility.until_timeout.now', return_value=now):
85+ with patch.object(client, 'get_status', return_value=status):
86+ with patch('subprocess.check_output', return_value=None):
87+ with patch.object(client, 'run', return_value=default):
88+ out = net_health.internet_connection(client)
89+ expected = {'1': False, '0': False}
90+ self.assertEqual(expected, out)
91+
92 def test_ensure_exposed(self):
93 args = parse_args([])
94 net_health = AssessNetworkHealth(args)

Subscribers

People subscribed via source and target branches