158
139
"/var/log/juju/unit-fill-logs-0.log", big_obj)
161
class TestTestDebugLog(TestCase):
163
def test_happy_log(self):
165
client.get_juju_output.return_value = '\n'*100
166
# Ensure that no exception is raised
167
assess_debug_log(client, timeout=120)
168
client.get_juju_output.assert_called_once_with(
169
"debug-log", "--lines=100", "--limit=100", timeout=120)
171
def test_unhappy_log(self):
173
client.get_juju_output.return_value = ''
174
# Ensure that no exception is raised
175
with self.assertRaises(LogRotateError):
176
assess_debug_log(client)
177
client.get_juju_output.assert_called_once_with(
178
"debug-log", "--lines=100", "--limit=100", timeout=180)
181
class TestMachineRoation(TestCase):
183
def test_respects_machine_id_0(self):
184
client = fake_juju_client()
186
client.deploy('fill-logs')
187
with patch('assess_log_rotation.test_rotation') as tr_mock:
188
assess_machine_rotation(client)
189
tr_mock.assert_called_once_with(
190
client, '/var/log/juju/machine-0.log', 'machine-0', 'fill-machine',
191
'machine-size', 'megs=300', 'machine=0')
193
def test_respects_machine_id_1(self):
194
client = fake_juju_client_optional_jes(jes_enabled=False)
196
client.deploy('fill-logs')
197
with patch('assess_log_rotation.test_rotation') as tr_mock:
198
assess_machine_rotation(client)
199
tr_mock.assert_called_once_with(
200
client, '/var/log/juju/machine-1.log', 'machine-1',
201
'fill-machine', 'machine-size', 'megs=300', 'machine=1')
204
142
class TestParseArgs(TestCase):
206
144
def test_parse_args(self):
207
args = parse_args(['b', 'c/juju', 'd', 'e', 'machine'])
208
self.assertEqual(args, Namespace(
209
agent='machine', env='b', juju_bin='c/juju', logs='d',
210
temp_env_name='e', debug=False, agent_stream=None, agent_url=None,
211
bootstrap_host=None, machine=[], keep_env=False,
212
region=None, series=None, upload_tools=False, verbose=20))
214
def test_parse_args_unit(self):
215
args = parse_args(['b', 'c/juju', 'd', 'e', 'unit'])
216
self.assertEqual('unit', args.agent)
219
class TestMakeClientFromArgs(TestCase):
222
def make_client_cxt(self):
223
with temp_env({'environments': {'foo': {}}}):
224
with patch('subprocess.check_output', return_value=''):
225
with patch('jujupy.EnvJujuClient.get_jes_command',
226
autospec=True, return_value='controller'):
227
with patch('jujupy.EnvJujuClient.juju',
228
autospec=True, return_value=''):
229
with patch('assess_log_rotation.tear_down',
230
autospec=True, return_value='') as td_func:
231
with patch.object(JujuData, 'load_yaml'):
234
def test_defaults(self):
235
with self.make_client_cxt() as td_func:
236
client = make_client_from_args(Namespace(
237
juju_bin='', debug=False, env='foo', temp_env_name='bar',
238
agent_url=None, agent_stream=None, series=None, region=None,
239
bootstrap_host=None, machine=[]
241
self.assertIsInstance(client, EnvJujuClient)
242
self.assertIn('/jes-homes/bar', client.env.juju_home)
243
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))