155
139
"/var/log/juju/unit-fill-logs-0.log", big_obj)
158
class TestTestDebugLog(TestCase):
160
def test_happy_log(self):
162
client.get_juju_output.return_value = '\n'*100
163
# Ensure that no exception is raised
164
assess_debug_log(client, timeout=120)
165
client.get_juju_output.assert_called_once_with(
166
"debug-log", "--lines=100", "--limit=100", timeout=120)
168
def test_unhappy_log(self):
170
client.get_juju_output.return_value = ''
171
# Ensure that no exception is raised
172
with self.assertRaises(LogRotateError):
173
assess_debug_log(client)
174
client.get_juju_output.assert_called_once_with(
175
"debug-log", "--lines=100", "--limit=100", timeout=180)
178
class TestMachineRoation(TestCase):
180
def test_respects_machine_id_0(self):
181
client = FakeJujuClient(jes_enabled=True)
183
client.deploy('fill-logs')
184
with patch('assess_log_rotation.test_rotation') as tr_mock:
185
assess_machine_rotation(client)
186
tr_mock.assert_called_once_with(
187
client, '/var/log/juju/machine-0.log', 'machine-0', 'fill-machine',
188
'machine-size', 'megs=300', 'machine=0')
190
def test_respects_machine_id_1(self):
191
client = FakeJujuClient(jes_enabled=False)
193
client.deploy('fill-logs')
194
with patch('assess_log_rotation.test_rotation') as tr_mock:
195
assess_machine_rotation(client)
196
tr_mock.assert_called_once_with(
197
client, '/var/log/juju/machine-1.log', 'machine-1',
198
'fill-machine', 'machine-size', 'megs=300', 'machine=1')
201
142
class TestParseArgs(TestCase):
203
144
def test_parse_args(self):
204
args = parse_args(['b', 'c/juju', 'd', 'e', 'machine'])
205
self.assertEqual(args, Namespace(
206
agent='machine', env='b', juju_bin='c/juju', logs='d',
207
temp_env_name='e', debug=False, agent_stream=None, agent_url=None,
208
bootstrap_host=None, machine=[], keep_env=False,
209
region=None, series=None, upload_tools=False, verbose=20))
211
def test_parse_args_unit(self):
212
args = parse_args(['b', 'c/juju', 'd', 'e', 'unit'])
213
self.assertEqual('unit', args.agent)
216
class TestMakeClientFromArgs(TestCase):
219
def make_client_cxt(self):
220
with temp_env({'environments': {'foo': {}}}):
221
with patch('subprocess.check_output', return_value=''):
222
with patch('jujupy.EnvJujuClient.get_jes_command',
223
autospec=True, return_value='controller'):
224
with patch('jujupy.EnvJujuClient.juju',
225
autospec=True, return_value=''):
226
with patch('assess_log_rotation.tear_down',
227
autospec=True, return_value='') as td_func:
228
with patch.object(JujuData, 'load_yaml'):
231
def test_defaults(self):
232
with self.make_client_cxt() as td_func:
233
client = make_client_from_args(Namespace(
234
juju_bin='', debug=False, env='foo', temp_env_name='bar',
235
agent_url=None, agent_stream=None, series=None, region=None,
236
bootstrap_host=None, machine=[]
238
self.assertIsInstance(client, EnvJujuClient)
239
self.assertIn('/jes-homes/bar', client.env.juju_home)
240
td_func.assert_called_once_with(client, True)
145
args = parse_args(['machine', 'b', 'c', 'd', 'e'])
146
self.assertEqual(args, Namespace(
147
agent='machine', juju_path='b', env_name='c', logs='d',
148
temp_env_name='e', debug=False))
150
def test_parse_args_debug(self):
151
args = parse_args(['--debug', 'unit', 'b', 'c', 'd', 'e'])
152
self.assertEqual(args, Namespace(
153
agent='unit', juju_path='b', env_name='c', logs='d',
154
temp_env_name='e', debug=True))