1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
#!/usr/bin/python3
# -*- Mode: Python; indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
import apt_check
import io
import unittest
import textwrap
def get_message(*args, **kwds):
with io.StringIO() as stream:
apt_check.write_human_readable_summary(stream, *args, **kwds)
return stream.getvalue()
class TestMotd(unittest.TestCase):
""" Validate /etc/motd text """
def test_esm_disabled_upto_date_esm_avail(self):
self.assertEqual(
get_message(upgrades=0, security_updates=0,
esm_updates=0, have_esm=False,
disabled_esm_updates=23),
textwrap.dedent(
"""
UA Infrastructure Extended Security Maintenance (ESM) is not enabled.
0 updates can be installed immediately.
0 of these updates are security updates.
Enable UA Infrastructure ESM to receive 23 additional security updates.
See https://ubuntu.com/esm or run: sudo ua status
""").lstrip())
def test_esm_disabled_security_esm_avail(self):
self.assertEqual(
get_message(upgrades=15, security_updates=7,
esm_updates=0, have_esm=False,
disabled_esm_updates=23),
textwrap.dedent(
"""
UA Infrastructure Extended Security Maintenance (ESM) is not enabled.
15 updates can be installed immediately.
7 of these updates are security updates.
To see these additional updates run: apt list --upgradable
Enable UA Infrastructure ESM to receive 23 additional security updates.
See https://ubuntu.com/esm or run: sudo ua status
""").lstrip())
def test_esm_disabled_security_no_esm_avail(self):
self.assertEqual(
get_message(upgrades=15, security_updates=7,
esm_updates=0, have_esm=False,
disabled_esm_updates=0),
textwrap.dedent(
"""
UA Infrastructure Extended Security Maintenance (ESM) is not enabled.
15 updates can be installed immediately.
7 of these updates are security updates.
To see these additional updates run: apt list --upgradable
Enable UA Infrastructure ESM to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo ua status
""").lstrip())
def test_esm_disabled_nosecurity(self):
self.assertEqual(
get_message(upgrades=15, security_updates=0,
esm_updates=0, have_esm=False,
disabled_esm_updates=0),
textwrap.dedent(
"""
UA Infrastructure Extended Security Maintenance (ESM) is not enabled.
15 updates can be installed immediately.
0 of these updates are security updates.
To see these additional updates run: apt list --upgradable
Enable UA Infrastructure ESM to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo ua status
""").lstrip())
def test_esm_disabled_noupdates(self):
self.assertEqual(
get_message(upgrades=0, security_updates=0,
esm_updates=0, have_esm=False,
disabled_esm_updates=0),
textwrap.dedent(
"""
UA Infrastructure Extended Security Maintenance (ESM) is not enabled.
0 updates can be installed immediately.
0 of these updates are security updates.
Enable UA Infrastructure ESM to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo ua status
""").lstrip())
def test_esm_enabled_nosecurity(self):
self.assertEqual(
get_message(upgrades=35, security_updates=0,
esm_updates=13, have_esm=True,
disabled_esm_updates=0),
textwrap.dedent(
"""
UA Infrastructure Extended Security Maintenance (ESM) is enabled.
35 updates can be installed immediately.
13 of these updates are provided through UA Infrastructure ESM.
0 of these updates are security updates.
To see these additional updates run: apt list --upgradable
""").lstrip())
def test_esm_enabled_somesecurity(self):
self.assertEqual(
get_message(upgrades=47, security_updates=7,
esm_updates=13, have_esm=True,
disabled_esm_updates=0),
textwrap.dedent(
"""
UA Infrastructure Extended Security Maintenance (ESM) is enabled.
47 updates can be installed immediately.
13 of these updates are provided through UA Infrastructure ESM.
7 of these updates are security updates.
To see these additional updates run: apt list --upgradable
""").lstrip())
def test_esm_enabled_noupdates(self):
self.assertEqual(
get_message(upgrades=0, security_updates=0,
esm_updates=0, have_esm=True,
disabled_esm_updates=0),
textwrap.dedent(
"""
UA Infrastructure Extended Security Maintenance (ESM) is enabled.
0 updates can be installed immediately.
0 of these updates are security updates.
""").lstrip())
if __name__ == "__main__":
import logging
logging.basicConfig(level=logging.DEBUG)
unittest.main()
|