langfun 0.1.2.dev202510310805__py3-none-any.whl → 0.1.2.dev202511020804__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of langfun might be problematic. Click here for more details.

@@ -17,8 +17,6 @@ import unittest
17
17
 
18
18
  from langfun.env import interface
19
19
  from langfun.env import test_utils
20
- from langfun.env.event_handlers import base as event_handler_base
21
-
22
20
 
23
21
  TestingEnvironment = test_utils.TestingEnvironment
24
22
  TestingSandbox = test_utils.TestingSandbox
@@ -26,453 +24,7 @@ TestingFeature = test_utils.TestingFeature
26
24
  TestingEventHandler = test_utils.TestingEventHandler
27
25
 
28
26
 
29
- class EnvironmentTests(unittest.TestCase):
30
-
31
- def test_basics(self):
32
- env = TestingEnvironment(
33
- image_ids=['test_image'],
34
- root_dir='/tmp',
35
- pool_size=0,
36
- features={'test_feature': TestingFeature()},
37
- outage_grace_period=1,
38
- outage_retry_interval=0,
39
- )
40
- self.assertIsNone(interface.Environment.current())
41
- self.assertEqual(env.image_ids, ['test_image'])
42
- self.assertFalse(env.supports_dynamic_image_loading)
43
- self.assertEqual(env.status, interface.Environment.Status.CREATED)
44
- self.assertFalse(env.is_online)
45
- self.assertEqual(env.min_pool_size('test_image'), 0)
46
- self.assertEqual(env.max_pool_size('test_image'), 0)
47
- self.assertEqual(env.sandbox_pool, {})
48
- self.assertEqual(env.id, interface.Environment.Id('testing-env'))
49
- self.assertEqual(env.outage_grace_period, 1)
50
- self.assertEqual(env.features['test_feature'].name, 'test_feature')
51
-
52
- self.assertIsNone(env.start_time)
53
-
54
- with env:
55
- self.assertEqual(env.status, interface.Environment.Status.ONLINE)
56
- self.assertIs(interface.Environment.current(), env)
57
- self.assertTrue(env.is_online)
58
- self.assertIsNotNone(env.start_time)
59
- self.assertEqual(env.offline_duration, 0.0)
60
- self.assertEqual(env.sandbox_pool, {})
61
- self.assertEqual(env.working_dir, '/tmp/testing-env')
62
-
63
- with env.sandbox(session_id='session1') as sb:
64
- self.assertEqual(
65
- sb.id, interface.Sandbox.Id(
66
- environment_id=env.id,
67
- image_id=sb.image_id,
68
- sandbox_id='0')
69
- )
70
- self.assertEqual(sb.session_id, 'session1')
71
- self.assertEqual(sb.working_dir, '/tmp/testing-env/test_image/0')
72
- self.assertTrue(sb.is_online)
73
- self.assertIs(sb.test_feature, sb.features['test_feature'])
74
- self.assertEqual(
75
- sb.test_feature.working_dir,
76
- '/tmp/testing-env/test_image/0/test_feature'
77
- )
78
- with self.assertRaises(AttributeError):
79
- _ = sb.test_feature2
80
- self.assertFalse(sb.is_online)
81
-
82
- with self.assertRaisesRegex(
83
- ValueError, 'Environment .* does not serve image ID .*'
84
- ):
85
- env.sandbox('test_image2')
86
-
87
- with env.test_feature() as feature:
88
- self.assertIsInstance(feature, TestingFeature)
89
- self.assertEqual(
90
- feature.sandbox.status, interface.Sandbox.Status.IN_SESSION
91
- )
92
- self.assertTrue(
93
- feature.sandbox.session_id.startswith('test_feature-session')
94
- )
95
-
96
- with self.assertRaises(AttributeError):
97
- _ = env.test_feature2
98
-
99
- def test_dynamic_image_loading(self):
100
- env = TestingEnvironment(
101
- image_ids=[],
102
- supports_dynamic_image_loading=True,
103
- pool_size=0,
104
- features={'test_feature': TestingFeature()},
105
- outage_grace_period=1,
106
- outage_retry_interval=0,
107
- )
108
- with env:
109
- with env.sandbox(image_id='test_image2') as sb:
110
- self.assertEqual(sb.image_id, 'test_image2')
111
-
112
- with self.assertRaisesRegex(
113
- ValueError, 'Environment .* does not have a default image ID.'
114
- ):
115
- env.sandbox()
116
-
117
- def test_dynamic_image_loading_with_pooling(self):
118
- env = TestingEnvironment(
119
- image_ids=[],
120
- supports_dynamic_image_loading=True,
121
- pool_size=2,
122
- features={'test_feature': TestingFeature()},
123
- outage_grace_period=1,
124
- outage_retry_interval=0,
125
- )
126
- with env:
127
- with env.sandbox(image_id='test_image'):
128
- self.assertEqual(len(env.sandbox_pool['test_image']), 1)
129
-
130
- with env.sandbox(image_id='test_image'):
131
- self.assertEqual(len(env.sandbox_pool['test_image']), 2)
132
-
133
- with self.assertRaises(interface.EnvironmentOverloadError):
134
- with env.sandbox(image_id='test_image'):
135
- pass
136
- self.assertEqual(len(env.sandbox_pool['test_image']), 2)
137
-
138
- with env.sandbox(image_id='test_image'):
139
- self.assertEqual(len(env.sandbox_pool['test_image']), 2)
140
-
141
- def test_image_feature_mappings(self):
142
- env = TestingEnvironment(
143
- image_ids=[
144
- 'test_image1',
145
- 'test_image2',
146
- ],
147
- features={
148
- 'test_feature': TestingFeature(
149
- applicable_images=['test_image1.*']
150
- ),
151
- 'test_feature2': TestingFeature(
152
- applicable_images=['test_image2.*']
153
- ),
154
- 'test_feature3': TestingFeature(
155
- applicable_images=['test_image.*']
156
- ),
157
- },
158
- pool_size=0,
159
- outage_grace_period=1,
160
- outage_retry_interval=0,
161
- sandbox_keepalive_interval=0,
162
- )
163
- with env:
164
- with env.sandbox(image_id='test_image1') as sb:
165
- self.assertIn('test_feature', sb.features)
166
- self.assertNotIn('test_feature2', sb.features)
167
- self.assertIn('test_feature3', sb.features)
168
-
169
- with env.sandbox(image_id='test_image2') as sb:
170
- self.assertNotIn('test_feature', sb.features)
171
- self.assertIn('test_feature2', sb.features)
172
- self.assertIn('test_feature3', sb.features)
173
-
174
- with env.test_feature() as feature:
175
- self.assertEqual(feature.sandbox.image_id, 'test_image1')
176
-
177
- with self.assertRaisesRegex(
178
- ValueError, 'Feature .* is not applicable to .*'
179
- ):
180
- with env.test_feature('test_image2'):
181
- pass
182
-
183
- with env.test_feature2() as feature:
184
- self.assertEqual(feature.sandbox.image_id, 'test_image2')
185
-
186
- with env.test_feature3() as feature:
187
- self.assertEqual(feature.sandbox.image_id, 'test_image1')
188
-
189
- with env.test_feature3('test_image2') as feature:
190
- self.assertEqual(feature.sandbox.image_id, 'test_image2')
191
-
192
- def test_feature_applicability_check(self):
193
- with self.assertRaisesRegex(
194
- ValueError, 'Feature .* is not applicable to .*'
195
- ):
196
- TestingEnvironment(
197
- image_ids=[
198
- 'test_image1',
199
- ],
200
- features={
201
- 'test_feature2': TestingFeature(
202
- applicable_images=['test_image2.*']
203
- ),
204
- },
205
- )
206
- env = TestingEnvironment(
207
- image_ids=[],
208
- supports_dynamic_image_loading=True,
209
- features={
210
- 'test_feature2': TestingFeature(
211
- applicable_images=['test_image2.*']
212
- ),
213
- },
214
- pool_size=0
215
- )
216
- with env:
217
- with self.assertRaisesRegex(
218
- ValueError, 'No image ID found for feature .*'
219
- ):
220
- with env.test_feature2():
221
- pass
222
-
223
- # Dynamically loaded IDs.
224
- with env.test_feature2('test_image2') as feature:
225
- self.assertEqual(feature.sandbox.image_id, 'test_image2')
226
-
227
- def test_pool_size(self):
228
- env = TestingEnvironment(
229
- image_ids=['test_image'],
230
- pool_size=1,
231
- outage_grace_period=1,
232
- outage_retry_interval=0,
233
- )
234
- self.assertEqual(env.min_pool_size('test_image'), 1)
235
- self.assertEqual(env.max_pool_size('test_image'), 1)
236
-
237
- env = TestingEnvironment(
238
- image_ids=['test_image'],
239
- pool_size=(0, 256),
240
- outage_grace_period=1,
241
- outage_retry_interval=0,
242
- )
243
- self.assertEqual(env.min_pool_size('test_image'), 0)
244
- self.assertEqual(env.max_pool_size('test_image'), 256)
245
-
246
- env = TestingEnvironment(
247
- image_ids=['test_image'],
248
- pool_size={
249
- 'test_.*': (0, 128),
250
- 'my.*': (5, 64),
251
- 'exact_image_name': 10,
252
- },
253
- outage_grace_period=1,
254
- outage_retry_interval=0,
255
- )
256
- self.assertEqual(env.min_pool_size('test_image'), 0)
257
- self.assertEqual(env.max_pool_size('test_image'), 128)
258
- self.assertEqual(env.min_pool_size('my_image'), 5)
259
- self.assertEqual(env.max_pool_size('my_image'), 64)
260
- self.assertEqual(env.min_pool_size('exact_image_name'), 10)
261
- self.assertEqual(env.max_pool_size('exact_image_name'), 10)
262
- self.assertEqual(env.min_pool_size('some_image'), 0) # default
263
- self.assertEqual(env.max_pool_size('some_image'), 256) # default
264
-
265
- def test_del(self):
266
- env = TestingEnvironment(
267
- features={'test_feature': TestingFeature()},
268
- pool_size=0,
269
- outage_grace_period=1,
270
- outage_retry_interval=0,
271
- sandbox_keepalive_interval=0,
272
- )
273
- env.start()
274
- sb = env.acquire()
275
- del sb
276
- del env
277
-
278
- def test_acquire_env_offline(self):
279
- env = TestingEnvironment(
280
- features={'test_feature': TestingFeature()},
281
- pool_size=0,
282
- outage_grace_period=1,
283
- outage_retry_interval=0,
284
- sandbox_keepalive_interval=0,
285
- )
286
- with self.assertRaises(interface.EnvironmentOutageError):
287
- env.acquire()
288
-
289
- def test_acquire_no_pooling(self):
290
- env = TestingEnvironment(
291
- features={'test_feature': TestingFeature()},
292
- pool_size=0,
293
- outage_grace_period=1,
294
- outage_retry_interval=0,
295
- sandbox_keepalive_interval=0,
296
- )
297
- with env:
298
- sb = env.acquire()
299
- self.assertEqual(sb.status, interface.Sandbox.Status.ACQUIRED)
300
- self.assertIsNone(env.working_dir)
301
- self.assertIsNone(sb.working_dir)
302
- self.assertIsNone(sb.test_feature.working_dir)
303
-
304
- def test_acquire_no_pooling_with_error(self):
305
- env = TestingEnvironment(
306
- features={
307
- 'test_feature': TestingFeature(
308
- simulate_setup_error=interface.SandboxStateError
309
- )
310
- },
311
- pool_size=0,
312
- outage_grace_period=1,
313
- outage_retry_interval=0,
314
- sandbox_keepalive_interval=0,
315
- )
316
- with env:
317
- with self.assertRaises(interface.EnvironmentOutageError):
318
- env.acquire()
319
-
320
- def test_acquire_with_pooling(self):
321
- env = TestingEnvironment(
322
- features={'test_feature': TestingFeature()},
323
- pool_size=1,
324
- outage_grace_period=1,
325
- outage_retry_interval=0,
326
- sandbox_keepalive_interval=0,
327
- )
328
- with env:
329
- sb = env.acquire()
330
- self.assertEqual(sb.status, interface.Sandbox.Status.ACQUIRED)
331
-
332
- def test_acquire_with_pooling_overload(self):
333
- env = TestingEnvironment(
334
- features={'test_feature': TestingFeature()},
335
- pool_size=1,
336
- outage_grace_period=1,
337
- outage_retry_interval=0,
338
- sandbox_keepalive_interval=0,
339
- )
340
- with env:
341
- sb = env.acquire()
342
- self.assertEqual(sb.status, interface.Sandbox.Status.ACQUIRED)
343
- with self.assertRaises(interface.EnvironmentOverloadError):
344
- env.acquire()
345
-
346
- def test_acquire_with_growing_pool(self):
347
- env = TestingEnvironment(
348
- features={'test_feature': TestingFeature()},
349
- pool_size=(1, 3),
350
- outage_grace_period=1,
351
- outage_retry_interval=0,
352
- sandbox_keepalive_interval=0,
353
- )
354
- with env:
355
- self.assertEqual(len(env.sandbox_pool['test_image']), 1)
356
- self.assertEqual(
357
- env.stats(),
358
- {
359
- 'sandbox': {
360
- 'test_image': {
361
- 'created': 0,
362
- 'setting_up': 0,
363
- 'ready': 1,
364
- 'acquired': 0,
365
- 'in_session': 0,
366
- 'exiting_session': 0,
367
- 'shutting_down': 0,
368
- 'offline': 0,
369
- }
370
- }
371
- }
372
- )
373
- sb = env.acquire()
374
- self.assertEqual(sb.status, interface.Sandbox.Status.ACQUIRED)
375
- self.assertEqual(
376
- env.stats(),
377
- {
378
- 'sandbox': {
379
- 'test_image': {
380
- 'created': 0,
381
- 'setting_up': 0,
382
- 'ready': 0,
383
- 'acquired': 1,
384
- 'in_session': 0,
385
- 'exiting_session': 0,
386
- 'shutting_down': 0,
387
- 'offline': 0,
388
- }
389
- }
390
- }
391
- )
392
- self.assertEqual(len(env.sandbox_pool['test_image']), 1)
393
- sb2 = env.acquire()
394
- self.assertEqual(sb2.status, interface.Sandbox.Status.ACQUIRED)
395
- self.assertEqual(len(env.sandbox_pool['test_image']), 2)
396
- self.assertEqual(
397
- env.stats(),
398
- {
399
- 'sandbox': {
400
- 'test_image': {
401
- 'created': 0,
402
- 'setting_up': 0,
403
- 'ready': 0,
404
- 'acquired': 2,
405
- 'in_session': 0,
406
- 'exiting_session': 0,
407
- 'shutting_down': 0,
408
- 'offline': 0,
409
- }
410
- }
411
- }
412
- )
413
- self.assertEqual(
414
- env.stats(),
415
- {
416
- 'sandbox': {}
417
- }
418
- )
419
-
420
- def test_acquire_with_growing_pool_failure(self):
421
- env = TestingEnvironment(
422
- features={'test_feature': TestingFeature()},
423
- pool_size=(1, 3),
424
- outage_grace_period=1,
425
- outage_retry_interval=0,
426
- sandbox_keepalive_interval=0,
427
- )
428
- with env:
429
- self.assertEqual(len(env.sandbox_pool), 1)
430
- sb = env.acquire()
431
- self.assertEqual(sb.status, interface.Sandbox.Status.ACQUIRED)
432
-
433
- # Make future sandbox setup to fail.
434
- env.features.test_feature.rebind(
435
- simulate_setup_error=interface.SandboxStateError,
436
- skip_notification=True
437
- )
438
- with self.assertRaises(interface.EnvironmentOutageError):
439
- env.acquire()
440
-
441
- def test_housekeep_error(self):
442
- env = TestingEnvironment(
443
- features={'test_feature': TestingFeature()},
444
- pool_size=1,
445
- proactive_session_setup=True,
446
- outage_grace_period=1,
447
- outage_retry_interval=0,
448
- sandbox_keepalive_interval=0,
449
- )
450
- with env:
451
- self.assertEqual(len(env.sandbox_pool), 1)
452
- self.assertIn('test_image', env.sandbox_pool)
453
- self.assertEqual(
454
- env.sandbox_pool['test_image'][0].status,
455
- interface.Sandbox.Status.READY
456
- )
457
- # Make future sandbox setup to fail.
458
- env.features.test_feature.rebind(
459
- simulate_setup_error=interface.SandboxStateError,
460
- skip_notification=True
461
- )
462
- with self.assertRaises(interface.SandboxStateError):
463
- with env.sandbox() as sb:
464
- sb.shell('bad command', raise_error=interface.SandboxStateError)
465
- self.assertEqual(sb.status, interface.Sandbox.Status.OFFLINE)
466
- self.assertEqual(len(sb.state_errors), 1)
467
- sb_offline_time = time.time()
468
- while time.time() - sb_offline_time < 10:
469
- if not env.is_online:
470
- break
471
- time.sleep(0.5)
472
- self.assertFalse(env.is_online)
473
-
474
-
475
- class SandboxStatusTests(unittest.TestCase):
27
+ class SandboxStateTests(unittest.TestCase):
476
28
 
477
29
  def setUp(self):
478
30
  super().setUp()
@@ -494,7 +46,7 @@ class SandboxStatusTests(unittest.TestCase):
494
46
  pool_size=pool_size,
495
47
  features=features,
496
48
  outage_grace_period=0,
497
- event_handlers=[self.event_handler],
49
+ event_handler=self.event_handler,
498
50
  outage_retry_interval=0,
499
51
  **kwargs
500
52
  )
@@ -508,39 +60,39 @@ class SandboxStatusTests(unittest.TestCase):
508
60
  )
509
61
  self.assertFalse(env.enable_pooling('test_image'))
510
62
  with env:
511
- with env.sandbox(session_id='session1') as sb:
63
+ with env.sandbox('session1') as sb:
512
64
  sb.shell('echo "hello"')
513
65
  self.assertEqual(
514
66
  self.event_handler.logs,
515
67
  [
516
68
  # pylint: disable=line-too-long
517
69
  '[testing-env] environment started',
518
- '[testing-env/test_image:0] shell: "feature1" setup',
70
+ '[testing-env/test_image:0@<idle>] shell: "feature1" setup',
519
71
  '[testing-env/test_image:0/feature1] feature setup',
520
- '[testing-env/test_image:0] shell: "feature2" setup',
72
+ '[testing-env/test_image:0@<idle>] shell: "feature2" setup',
521
73
  '[testing-env/test_image:0/feature2] feature setup',
522
74
  '[testing-env/test_image:0] created -> ready',
523
75
  '[testing-env/test_image:0] sandbox started',
524
76
  '[testing-env/test_image:0] ready -> acquired',
525
77
  '[testing-env/test_image:0] acquired -> setting_up',
526
- '[testing-env/test_image:0/session1] shell: "feature1" setup session',
527
- '[testing-env/test_image:0/feature1] feature setup session',
528
- '[testing-env/test_image:0/session1] shell: "feature2" setup session',
529
- '[testing-env/test_image:0/feature2] feature setup session',
78
+ '[testing-env/test_image:0@session1] shell: "feature1" setup session',
79
+ '[testing-env/test_image:0/feature1@session1] feature setup session',
80
+ '[testing-env/test_image:0@session1] shell: "feature2" setup session',
81
+ '[testing-env/test_image:0/feature2@session1] feature setup session',
530
82
  '[testing-env/test_image:0] setting_up -> in_session',
531
83
  "[testing-env/test_image:0] session 'session1' started",
532
- '[testing-env/test_image:0/session1] shell: echo "hello"',
84
+ '[testing-env/test_image:0@session1] shell: echo "hello"',
533
85
  '[testing-env/test_image:0] in_session -> exiting_session',
534
- '[testing-env/test_image:0/session1] shell: "feature1" teardown session',
535
- '[testing-env/test_image:0/feature1] feature teardown session',
536
- '[testing-env/test_image:0/session1] shell: "feature2" teardown session',
537
- '[testing-env/test_image:0/feature2] feature teardown session',
86
+ '[testing-env/test_image:0@session1] shell: "feature1" teardown session',
87
+ '[testing-env/test_image:0/feature1@session1] feature teardown session',
88
+ '[testing-env/test_image:0@session1] shell: "feature2" teardown session',
89
+ '[testing-env/test_image:0/feature2@session1] feature teardown session',
538
90
  "[testing-env/test_image:0] session 'session1' ended",
539
91
  '[testing-env/test_image:0] exiting_session -> acquired',
540
92
  '[testing-env/test_image:0] acquired -> shutting_down',
541
- '[testing-env/test_image:0] shell: "feature1" teardown',
93
+ '[testing-env/test_image:0@<idle>] shell: "feature1" teardown',
542
94
  '[testing-env/test_image:0/feature1] feature teardown',
543
- '[testing-env/test_image:0] shell: "feature2" teardown',
95
+ '[testing-env/test_image:0@<idle>] shell: "feature2" teardown',
544
96
  '[testing-env/test_image:0/feature2] feature teardown',
545
97
  '[testing-env/test_image:0] shutting_down -> offline',
546
98
  '[testing-env/test_image:0] sandbox shutdown'
@@ -559,7 +111,7 @@ class SandboxStatusTests(unittest.TestCase):
559
111
  )
560
112
  self.assertTrue(env.enable_pooling('test_image'))
561
113
  with env:
562
- with env.sandbox(session_id='session1') as sb:
114
+ with env.sandbox('session1') as sb:
563
115
  sb.shell('echo "hello"')
564
116
  sb.wait_until_not(
565
117
  (
@@ -572,14 +124,14 @@ class SandboxStatusTests(unittest.TestCase):
572
124
  self.event_handler.logs,
573
125
  [
574
126
  # pylint: disable=line-too-long
575
- '[testing-env/test_image:0:0] shell: "feature1" setup',
127
+ '[testing-env/test_image:0:0@<idle>] shell: "feature1" setup',
576
128
  '[testing-env/test_image:0:0/feature1] feature setup',
577
- '[testing-env/test_image:0:0] shell: "feature2" setup',
129
+ '[testing-env/test_image:0:0@<idle>] shell: "feature2" setup',
578
130
  '[testing-env/test_image:0:0/feature2] feature setup',
579
- '[testing-env/test_image:0:0] shell: "feature1" setup session',
580
- '[testing-env/test_image:0:0/feature1] feature setup session',
581
- '[testing-env/test_image:0:0] shell: "feature2" setup session',
582
- '[testing-env/test_image:0:0/feature2] feature setup session',
131
+ '[testing-env/test_image:0:0@<idle>] shell: "feature1" setup session',
132
+ '[testing-env/test_image:0:0/feature1@<idle>] feature setup session',
133
+ '[testing-env/test_image:0:0@<idle>] shell: "feature2" setup session',
134
+ '[testing-env/test_image:0:0/feature2@<idle>] feature setup session',
583
135
  '[testing-env/test_image:0:0] created -> ready',
584
136
  '[testing-env/test_image:0:0] sandbox started',
585
137
  '[testing-env] environment started',
@@ -587,36 +139,31 @@ class SandboxStatusTests(unittest.TestCase):
587
139
  '[testing-env/test_image:0:0] acquired -> setting_up',
588
140
  '[testing-env/test_image:0:0] setting_up -> in_session',
589
141
  "[testing-env/test_image:0:0] session 'session1' started",
590
- '[testing-env/test_image:0:0/session1] shell: echo "hello"',
142
+ '[testing-env/test_image:0:0@session1] shell: echo "hello"',
591
143
  '[testing-env/test_image:0:0] in_session -> exiting_session',
592
- '[testing-env/test_image:0:0/session1] shell: "feature1" teardown session',
593
- '[testing-env/test_image:0:0/feature1] feature teardown session',
594
- '[testing-env/test_image:0:0/session1] shell: "feature2" teardown session',
595
- '[testing-env/test_image:0:0/feature2] feature teardown session',
144
+ '[testing-env/test_image:0:0@session1] shell: "feature1" teardown session',
145
+ '[testing-env/test_image:0:0/feature1@session1] feature teardown session',
146
+ '[testing-env/test_image:0:0@session1] shell: "feature2" teardown session',
147
+ '[testing-env/test_image:0:0/feature2@session1] feature teardown session',
596
148
  "[testing-env/test_image:0:0] session 'session1' ended",
597
149
  '[testing-env/test_image:0:0] exiting_session -> setting_up',
598
- '[testing-env/test_image:0:0] shell: "feature1" setup session',
599
- '[testing-env/test_image:0:0/feature1] feature setup session',
600
- '[testing-env/test_image:0:0] shell: "feature2" setup session',
601
- '[testing-env/test_image:0:0/feature2] feature setup session',
150
+ '[testing-env/test_image:0:0@<idle>] shell: "feature1" setup session',
151
+ '[testing-env/test_image:0:0/feature1@<idle>] feature setup session',
152
+ '[testing-env/test_image:0:0@<idle>] shell: "feature2" setup session',
153
+ '[testing-env/test_image:0:0/feature2@<idle>] feature setup session',
602
154
  '[testing-env/test_image:0:0] setting_up -> ready'
603
155
  # pylint: enable=line-too-long
604
156
  ]
605
157
  )
606
158
 
607
- def test_practive_session_setup_with_setup_session_error(self):
159
+ def test_proactive_session_setup_with_setup_session_error(self):
608
160
  env = self._create_env(
609
161
  features={'test_feature': TestingFeature(setup_session_delay=0.5)},
610
162
  pool_size=1,
611
- )
612
- event_handler = TestingEventHandler(
613
- log_sandbox_status=True,
614
- log_feature_setup=True,
615
- log_session_setup=True,
163
+ housekeep_interval=10.0,
616
164
  )
617
165
  with env:
618
- with env.sandbox(session_id='session1') as sb:
619
- sb.add_event_handler(event_handler)
166
+ with env.sandbox('session1') as sb:
620
167
  sb.test_feature.rebind(
621
168
  simulate_setup_session_error=interface.SandboxStateError,
622
169
  skip_notification=True
@@ -630,17 +177,28 @@ class SandboxStatusTests(unittest.TestCase):
630
177
  self.assertEqual(len(sb.state_errors), 1)
631
178
  self.assertEqual(sb.status, interface.Sandbox.Status.OFFLINE)
632
179
  self.assertEqual(
633
- event_handler.logs,
180
+ self.event_handler.logs,
634
181
  [
635
182
  # pylint: disable=line-too-long
183
+ '[testing-env/test_image:0:0@<idle>] shell: "test_feature" setup',
184
+ '[testing-env/test_image:0:0/test_feature] feature setup',
185
+ '[testing-env/test_image:0:0@<idle>] shell: "test_feature" setup session',
186
+ '[testing-env/test_image:0:0/test_feature@<idle>] feature setup session',
187
+ '[testing-env/test_image:0:0] created -> ready',
188
+ '[testing-env/test_image:0:0] sandbox started',
189
+ '[testing-env] environment started',
190
+ '[testing-env/test_image:0:0] ready -> acquired',
191
+ '[testing-env/test_image:0:0] acquired -> setting_up',
192
+ '[testing-env/test_image:0:0] setting_up -> in_session',
193
+ "[testing-env/test_image:0:0] session 'session1' started",
636
194
  '[testing-env/test_image:0:0] in_session -> exiting_session',
637
- '[testing-env/test_image:0:0/session1] shell: "test_feature" teardown session',
638
- '[testing-env/test_image:0:0/test_feature] feature teardown session',
195
+ '[testing-env/test_image:0:0@session1] shell: "test_feature" teardown session',
196
+ '[testing-env/test_image:0:0/test_feature@session1] feature teardown session',
639
197
  "[testing-env/test_image:0:0] session 'session1' ended",
640
198
  '[testing-env/test_image:0:0] exiting_session -> setting_up',
641
- '[testing-env/test_image:0:0/test_feature] feature setup session with SandboxStateError', # pylint: disable=line-too-long
199
+ '[testing-env/test_image:0:0/test_feature@<idle>] feature setup session with SandboxStateError',
642
200
  '[testing-env/test_image:0:0] setting_up -> shutting_down',
643
- '[testing-env/test_image:0:0] shell: "test_feature" teardown',
201
+ '[testing-env/test_image:0:0@<idle>] shell: "test_feature" teardown',
644
202
  '[testing-env/test_image:0:0/test_feature] feature teardown',
645
203
  '[testing-env/test_image:0:0] shutting_down -> offline',
646
204
  '[testing-env/test_image:0:0] sandbox shutdown'
@@ -658,7 +216,7 @@ class SandboxStatusTests(unittest.TestCase):
658
216
  )
659
217
  with env:
660
218
  with self.assertRaises(ValueError):
661
- with env.sandbox(session_id='session1'):
219
+ with env.sandbox('session1'):
662
220
  pass
663
221
  self.assertTrue(env.is_online)
664
222
  self.assertEqual(
@@ -708,45 +266,44 @@ class SandboxStatusTests(unittest.TestCase):
708
266
  )
709
267
  with env:
710
268
  with self.assertRaises(ValueError):
711
- with env.sandbox(session_id='session1') as sb:
269
+ with env.sandbox('session1') as sb:
712
270
  sb.shell('echo "hello"')
713
271
  self.assertEqual(len(sb.state_errors), 0)
714
-
715
272
  self.assertEqual(
716
273
  self.event_handler.logs,
717
274
  [
718
275
  # pylint: disable=line-too-long
719
276
  '[testing-env] environment started',
720
- '[testing-env/test_image:0] shell: "feature1" setup',
277
+ '[testing-env/test_image:0@<idle>] shell: "feature1" setup',
721
278
  '[testing-env/test_image:0/feature1] feature setup',
722
- '[testing-env/test_image:0] shell: "feature2" setup',
279
+ '[testing-env/test_image:0@<idle>] shell: "feature2" setup',
723
280
  '[testing-env/test_image:0/feature2] feature setup',
724
281
  '[testing-env/test_image:0] created -> ready',
725
282
  '[testing-env/test_image:0] sandbox started',
726
283
  '[testing-env/test_image:0] ready -> acquired',
727
284
  '[testing-env/test_image:0] acquired -> setting_up',
728
- '[testing-env/test_image:0/session1] shell: "feature1" setup session',
729
- '[testing-env/test_image:0/feature1] feature setup session',
730
- '[testing-env/test_image:0/session1] shell: "feature2" setup session',
731
- '[testing-env/test_image:0/feature2] feature setup session',
285
+ '[testing-env/test_image:0@session1] shell: "feature1" setup session',
286
+ '[testing-env/test_image:0/feature1@session1] feature setup session',
287
+ '[testing-env/test_image:0@session1] shell: "feature2" setup session',
288
+ '[testing-env/test_image:0/feature2@session1] feature setup session',
732
289
  '[testing-env/test_image:0] setting_up -> in_session',
733
290
  "[testing-env/test_image:0] session 'session1' started",
734
- '[testing-env/test_image:0/session1] shell: echo "hello"',
291
+ '[testing-env/test_image:0@session1] shell: echo "hello"',
735
292
  '[testing-env/test_image:0] in_session -> exiting_session',
736
- '[testing-env/test_image:0/session1] shell: "feature1" teardown session',
737
- '[testing-env/test_image:0/feature1] feature teardown session',
738
- '[testing-env/test_image:0/session1] shell: "feature2" teardown session',
739
- '[testing-env/test_image:0/feature2] feature teardown session',
293
+ '[testing-env/test_image:0@session1] shell: "feature1" teardown session',
294
+ '[testing-env/test_image:0/feature1@session1] feature teardown session',
295
+ '[testing-env/test_image:0@session1] shell: "feature2" teardown session',
296
+ '[testing-env/test_image:0/feature2@session1] feature teardown session',
740
297
  "[testing-env/test_image:0] session 'session1' ended",
741
298
  '[testing-env/test_image:0] exiting_session -> acquired',
742
299
  '[testing-env/test_image:0] acquired -> shutting_down',
743
- '[testing-env/test_image:0] shell: "feature1" teardown',
300
+ '[testing-env/test_image:0@<idle>] shell: "feature1" teardown',
744
301
  '[testing-env/test_image:0/feature1] feature teardown',
745
- '[testing-env/test_image:0] shell: "feature2" teardown',
302
+ '[testing-env/test_image:0@<idle>] shell: "feature2" teardown',
746
303
  '[testing-env/test_image:0/feature2] feature teardown',
747
304
  '[testing-env/test_image:0] shutting_down -> offline',
748
305
  '[testing-env/test_image:0] sandbox shutdown with ValueError',
749
- '[testing-env] environment shutdown'
306
+ '[testing-env] environment shutdown',
750
307
  # pylint: enable=line-too-long
751
308
  ]
752
309
  )
@@ -768,21 +325,21 @@ class SandboxStatusTests(unittest.TestCase):
768
325
  self.event_handler.logs,
769
326
  [
770
327
  # pylint: disable=line-too-long
771
- '[testing-env/test_image:0:0] shell: "feature1" setup',
328
+ '[testing-env/test_image:0:0@<idle>] shell: "feature1" setup',
772
329
  '[testing-env/test_image:0:0/feature1] feature setup',
773
- '[testing-env/test_image:0:0] shell: "feature2" setup',
330
+ '[testing-env/test_image:0:0@<idle>] shell: "feature2" setup',
774
331
  '[testing-env/test_image:0:0/feature2] feature setup',
775
- '[testing-env/test_image:0:0] shell: "feature1" setup session',
776
- '[testing-env/test_image:0:0/feature1] feature setup session',
777
- '[testing-env/test_image:0:0] shell: "feature2" setup session',
778
- '[testing-env/test_image:0:0/feature2] feature setup session',
332
+ '[testing-env/test_image:0:0@<idle>] shell: "feature1" setup session',
333
+ '[testing-env/test_image:0:0/feature1@<idle>] feature setup session',
334
+ '[testing-env/test_image:0:0@<idle>] shell: "feature2" setup session',
335
+ '[testing-env/test_image:0:0/feature2@<idle>] feature setup session',
779
336
  '[testing-env/test_image:0:0] created -> ready',
780
337
  '[testing-env/test_image:0:0] sandbox started',
781
338
  '[testing-env] environment started',
782
339
  '[testing-env/test_image:0:0] ready -> shutting_down',
783
- '[testing-env/test_image:0:0] shell: "feature1" teardown',
340
+ '[testing-env/test_image:0:0@<idle>] shell: "feature1" teardown',
784
341
  '[testing-env/test_image:0:0/feature1] feature teardown',
785
- '[testing-env/test_image:0:0] shell: "feature2" teardown',
342
+ '[testing-env/test_image:0:0@<idle>] shell: "feature2" teardown',
786
343
  '[testing-env/test_image:0:0/feature2] feature teardown',
787
344
  '[testing-env/test_image:0:0] shutting_down -> offline',
788
345
  '[testing-env/test_image:0:0] sandbox shutdown with ValueError',
@@ -800,44 +357,45 @@ class SandboxStatusTests(unittest.TestCase):
800
357
  simulate_shutdown_error=interface.SandboxStateError,
801
358
  )
802
359
  with env:
803
- with env.sandbox(session_id='session1') as sb:
360
+ with env.sandbox('session1') as sb:
804
361
  sb.shell('echo "hello"')
805
362
  self.assertEqual(len(sb.state_errors), 1)
363
+
806
364
  self.assertEqual(
807
365
  self.event_handler.logs,
808
366
  [
809
367
  # pylint: disable=line-too-long
810
368
  '[testing-env] environment started',
811
- '[testing-env/test_image:0] shell: "feature1" setup',
369
+ '[testing-env/test_image:0@<idle>] shell: "feature1" setup',
812
370
  '[testing-env/test_image:0/feature1] feature setup',
813
- '[testing-env/test_image:0] shell: "feature2" setup',
371
+ '[testing-env/test_image:0@<idle>] shell: "feature2" setup',
814
372
  '[testing-env/test_image:0/feature2] feature setup',
815
373
  '[testing-env/test_image:0] created -> ready',
816
374
  '[testing-env/test_image:0] sandbox started',
817
375
  '[testing-env/test_image:0] ready -> acquired',
818
376
  '[testing-env/test_image:0] acquired -> setting_up',
819
- '[testing-env/test_image:0/session1] shell: "feature1" setup session',
820
- '[testing-env/test_image:0/feature1] feature setup session',
821
- '[testing-env/test_image:0/session1] shell: "feature2" setup session',
822
- '[testing-env/test_image:0/feature2] feature setup session',
377
+ '[testing-env/test_image:0@session1] shell: "feature1" setup session',
378
+ '[testing-env/test_image:0/feature1@session1] feature setup session',
379
+ '[testing-env/test_image:0@session1] shell: "feature2" setup session',
380
+ '[testing-env/test_image:0/feature2@session1] feature setup session',
823
381
  '[testing-env/test_image:0] setting_up -> in_session',
824
382
  "[testing-env/test_image:0] session 'session1' started",
825
- '[testing-env/test_image:0/session1] shell: echo "hello"',
383
+ '[testing-env/test_image:0@session1] shell: echo "hello"',
826
384
  '[testing-env/test_image:0] in_session -> exiting_session',
827
- '[testing-env/test_image:0/session1] shell: "feature1" teardown session',
828
- '[testing-env/test_image:0/feature1] feature teardown session',
829
- '[testing-env/test_image:0/session1] shell: "feature2" teardown session',
830
- '[testing-env/test_image:0/feature2] feature teardown session',
385
+ '[testing-env/test_image:0@session1] shell: "feature1" teardown session',
386
+ '[testing-env/test_image:0/feature1@session1] feature teardown session',
387
+ '[testing-env/test_image:0@session1] shell: "feature2" teardown session',
388
+ '[testing-env/test_image:0/feature2@session1] feature teardown session',
831
389
  "[testing-env/test_image:0] session 'session1' ended",
832
390
  '[testing-env/test_image:0] exiting_session -> acquired',
833
391
  '[testing-env/test_image:0] acquired -> shutting_down',
834
- '[testing-env/test_image:0] shell: "feature1" teardown',
392
+ '[testing-env/test_image:0@<idle>] shell: "feature1" teardown',
835
393
  '[testing-env/test_image:0/feature1] feature teardown',
836
- '[testing-env/test_image:0] shell: "feature2" teardown',
394
+ '[testing-env/test_image:0@<idle>] shell: "feature2" teardown',
837
395
  '[testing-env/test_image:0/feature2] feature teardown',
838
396
  '[testing-env/test_image:0] shutting_down -> offline',
839
397
  '[testing-env/test_image:0] sandbox shutdown with SandboxStateError',
840
- '[testing-env] environment shutdown'
398
+ '[testing-env] environment shutdown',
841
399
  # pylint: enable=line-too-long
842
400
  ]
843
401
  )
@@ -853,24 +411,24 @@ class SandboxStatusTests(unittest.TestCase):
853
411
  )
854
412
  with env:
855
413
  with self.assertRaises(ValueError):
856
- with env.sandbox(session_id='session1'):
414
+ with env.sandbox('session1'):
857
415
  pass
858
416
  self.assertEqual(
859
417
  self.event_handler.logs,
860
418
  [
861
419
  # pylint: disable=line-too-long
862
420
  '[testing-env] environment started',
863
- '[testing-env/test_image:0] shell: "feature1" setup',
421
+ '[testing-env/test_image:0@<idle>] shell: "feature1" setup',
864
422
  '[testing-env/test_image:0/feature1] feature setup',
865
423
  '[testing-env/test_image:0/feature2] feature setup with ValueError',
866
424
  '[testing-env/test_image:0] sandbox started with ValueError',
867
425
  '[testing-env/test_image:0] created -> shutting_down',
868
- '[testing-env/test_image:0] shell: "feature1" teardown',
426
+ '[testing-env/test_image:0@<idle>] shell: "feature1" teardown',
869
427
  '[testing-env/test_image:0/feature1] feature teardown',
870
- '[testing-env/test_image:0] shell: "feature2" teardown',
428
+ '[testing-env/test_image:0@<idle>] shell: "feature2" teardown',
871
429
  '[testing-env/test_image:0/feature2] feature teardown',
872
430
  '[testing-env/test_image:0] shutting_down -> offline',
873
- '[testing-env/test_image:0] sandbox shutdown',
431
+ '[testing-env/test_image:0] sandbox shutdown'
874
432
  # pylint: enable=line-too-long
875
433
  ]
876
434
  )
@@ -886,7 +444,7 @@ class SandboxStatusTests(unittest.TestCase):
886
444
  )
887
445
  with env:
888
446
  with self.assertRaises(interface.EnvironmentOutageError):
889
- with env.sandbox(session_id='session1'):
447
+ with env.sandbox('session1'):
890
448
  pass
891
449
  self.assertEqual(
892
450
  self.event_handler.logs,
@@ -896,7 +454,7 @@ class SandboxStatusTests(unittest.TestCase):
896
454
  '[testing-env/test_image:0/feature1] feature setup with SandboxStateError',
897
455
  '[testing-env/test_image:0] sandbox started with SandboxStateError',
898
456
  '[testing-env/test_image:0] created -> shutting_down',
899
- '[testing-env/test_image:0] shell: "feature1" teardown',
457
+ '[testing-env/test_image:0@<idle>] shell: "feature1" teardown',
900
458
  '[testing-env/test_image:0/feature1] feature teardown',
901
459
  '[testing-env/test_image:0] shutting_down -> offline',
902
460
  '[testing-env/test_image:0] sandbox shutdown',
@@ -916,36 +474,36 @@ class SandboxStatusTests(unittest.TestCase):
916
474
  )
917
475
  with env:
918
476
  with self.assertRaises(interface.FeatureTeardownError):
919
- with env.sandbox(session_id='session1'):
477
+ with env.sandbox('session1'):
920
478
  pass
921
479
  self.assertEqual(
922
480
  self.event_handler.logs,
923
481
  [
924
482
  # pylint: disable=line-too-long
925
483
  '[testing-env] environment started',
926
- '[testing-env/test_image:0] shell: "feature1" setup',
484
+ '[testing-env/test_image:0@<idle>] shell: "feature1" setup',
927
485
  '[testing-env/test_image:0/feature1] feature setup',
928
- '[testing-env/test_image:0] shell: "feature2" setup',
486
+ '[testing-env/test_image:0@<idle>] shell: "feature2" setup',
929
487
  '[testing-env/test_image:0/feature2] feature setup',
930
488
  '[testing-env/test_image:0] created -> ready',
931
489
  '[testing-env/test_image:0] sandbox started',
932
490
  '[testing-env/test_image:0] ready -> acquired',
933
491
  '[testing-env/test_image:0] acquired -> setting_up',
934
- '[testing-env/test_image:0/session1] shell: "feature1" setup session',
935
- '[testing-env/test_image:0/feature1] feature setup session',
936
- '[testing-env/test_image:0/session1] shell: "feature2" setup session',
937
- '[testing-env/test_image:0/feature2] feature setup session',
492
+ '[testing-env/test_image:0@session1] shell: "feature1" setup session',
493
+ '[testing-env/test_image:0/feature1@session1] feature setup session',
494
+ '[testing-env/test_image:0@session1] shell: "feature2" setup session',
495
+ '[testing-env/test_image:0/feature2@session1] feature setup session',
938
496
  '[testing-env/test_image:0] setting_up -> in_session',
939
497
  "[testing-env/test_image:0] session 'session1' started",
940
498
  '[testing-env/test_image:0] in_session -> exiting_session',
941
- '[testing-env/test_image:0/session1] shell: "feature1" teardown session',
942
- '[testing-env/test_image:0/feature1] feature teardown session',
943
- '[testing-env/test_image:0/session1] shell: "feature2" teardown session',
944
- '[testing-env/test_image:0/feature2] feature teardown session',
499
+ '[testing-env/test_image:0@session1] shell: "feature1" teardown session',
500
+ '[testing-env/test_image:0/feature1@session1] feature teardown session',
501
+ '[testing-env/test_image:0@session1] shell: "feature2" teardown session',
502
+ '[testing-env/test_image:0/feature2@session1] feature teardown session',
945
503
  "[testing-env/test_image:0] session 'session1' ended",
946
504
  '[testing-env/test_image:0] exiting_session -> acquired',
947
505
  '[testing-env/test_image:0] acquired -> shutting_down',
948
- '[testing-env/test_image:0] shell: "feature1" teardown',
506
+ '[testing-env/test_image:0@<idle>] shell: "feature1" teardown',
949
507
  '[testing-env/test_image:0/feature1] feature teardown',
950
508
  '[testing-env/test_image:0/feature2] feature teardown with ValueError',
951
509
  '[testing-env/test_image:0] shutting_down -> offline',
@@ -965,7 +523,7 @@ class SandboxStatusTests(unittest.TestCase):
965
523
  },
966
524
  )
967
525
  with env:
968
- with env.sandbox(session_id='session1') as sb:
526
+ with env.sandbox('session1') as sb:
969
527
  pass
970
528
  self.assertEqual(len(sb.state_errors), 1)
971
529
  self.assertEqual(
@@ -973,30 +531,30 @@ class SandboxStatusTests(unittest.TestCase):
973
531
  [
974
532
  # pylint: disable=line-too-long
975
533
  '[testing-env] environment started',
976
- '[testing-env/test_image:0] shell: "feature1" setup',
534
+ '[testing-env/test_image:0@<idle>] shell: "feature1" setup',
977
535
  '[testing-env/test_image:0/feature1] feature setup',
978
- '[testing-env/test_image:0] shell: "feature2" setup',
536
+ '[testing-env/test_image:0@<idle>] shell: "feature2" setup',
979
537
  '[testing-env/test_image:0/feature2] feature setup',
980
538
  '[testing-env/test_image:0] created -> ready',
981
539
  '[testing-env/test_image:0] sandbox started',
982
540
  '[testing-env/test_image:0] ready -> acquired',
983
541
  '[testing-env/test_image:0] acquired -> setting_up',
984
- '[testing-env/test_image:0/session1] shell: "feature1" setup session',
985
- '[testing-env/test_image:0/feature1] feature setup session',
986
- '[testing-env/test_image:0/session1] shell: "feature2" setup session',
987
- '[testing-env/test_image:0/feature2] feature setup session',
542
+ '[testing-env/test_image:0@session1] shell: "feature1" setup session',
543
+ '[testing-env/test_image:0/feature1@session1] feature setup session',
544
+ '[testing-env/test_image:0@session1] shell: "feature2" setup session',
545
+ '[testing-env/test_image:0/feature2@session1] feature setup session',
988
546
  '[testing-env/test_image:0] setting_up -> in_session',
989
547
  "[testing-env/test_image:0] session 'session1' started",
990
548
  '[testing-env/test_image:0] in_session -> exiting_session',
991
- '[testing-env/test_image:0/session1] shell: "feature1" teardown session',
992
- '[testing-env/test_image:0/feature1] feature teardown session',
993
- '[testing-env/test_image:0/session1] shell: "feature2" teardown session',
994
- '[testing-env/test_image:0/feature2] feature teardown session',
549
+ '[testing-env/test_image:0@session1] shell: "feature1" teardown session',
550
+ '[testing-env/test_image:0/feature1@session1] feature teardown session',
551
+ '[testing-env/test_image:0@session1] shell: "feature2" teardown session',
552
+ '[testing-env/test_image:0/feature2@session1] feature teardown session',
995
553
  "[testing-env/test_image:0] session 'session1' ended",
996
554
  '[testing-env/test_image:0] exiting_session -> acquired',
997
555
  '[testing-env/test_image:0] acquired -> shutting_down',
998
- '[testing-env/test_image:0/feature1] feature teardown with SandboxStateError', # pylint: disable=line-too-long
999
- '[testing-env/test_image:0] shell: "feature2" teardown',
556
+ '[testing-env/test_image:0/feature1] feature teardown with SandboxStateError',
557
+ '[testing-env/test_image:0@<idle>] shell: "feature2" teardown',
1000
558
  '[testing-env/test_image:0/feature2] feature teardown',
1001
559
  '[testing-env/test_image:0] shutting_down -> offline',
1002
560
  '[testing-env/test_image:0] sandbox shutdown with FeatureTeardownError',
@@ -1015,32 +573,32 @@ class SandboxStatusTests(unittest.TestCase):
1015
573
  )
1016
574
  with env:
1017
575
  with self.assertRaises(ValueError):
1018
- with env.sandbox(session_id='session1') as sb:
576
+ with env.sandbox('session1') as sb:
1019
577
  sb.shell('echo "hello"')
1020
578
  self.assertEqual(
1021
579
  self.event_handler.logs,
1022
580
  [
1023
581
  # pylint: disable=line-too-long
1024
582
  '[testing-env] environment started',
1025
- '[testing-env/test_image:0] shell: "feature1" setup',
583
+ '[testing-env/test_image:0@<idle>] shell: "feature1" setup',
1026
584
  '[testing-env/test_image:0/feature1] feature setup',
1027
- '[testing-env/test_image:0] shell: "feature2" setup',
585
+ '[testing-env/test_image:0@<idle>] shell: "feature2" setup',
1028
586
  '[testing-env/test_image:0/feature2] feature setup',
1029
587
  '[testing-env/test_image:0] created -> ready',
1030
588
  '[testing-env/test_image:0] sandbox started',
1031
589
  '[testing-env/test_image:0] ready -> acquired',
1032
590
  '[testing-env/test_image:0] acquired -> setting_up',
1033
- '[testing-env/test_image:0/session1] shell: "feature1" setup session',
1034
- '[testing-env/test_image:0/feature1] feature setup session',
1035
- '[testing-env/test_image:0/feature2] feature setup session with ValueError',
591
+ '[testing-env/test_image:0@session1] shell: "feature1" setup session',
592
+ '[testing-env/test_image:0/feature1@session1] feature setup session',
593
+ '[testing-env/test_image:0/feature2@session1] feature setup session with ValueError',
1036
594
  "[testing-env/test_image:0] session 'session1' started with ValueError",
1037
595
  '[testing-env/test_image:0] setting_up -> shutting_down',
1038
- '[testing-env/test_image:0/session1] shell: "feature1" teardown',
596
+ '[testing-env/test_image:0@session1] shell: "feature1" teardown',
1039
597
  '[testing-env/test_image:0/feature1] feature teardown',
1040
- '[testing-env/test_image:0/session1] shell: "feature2" teardown',
598
+ '[testing-env/test_image:0@session1] shell: "feature2" teardown',
1041
599
  '[testing-env/test_image:0/feature2] feature teardown',
1042
600
  '[testing-env/test_image:0] shutting_down -> offline',
1043
- '[testing-env/test_image:0] sandbox shutdown',
601
+ '[testing-env/test_image:0] sandbox shutdown'
1044
602
  # pylint: enable=line-too-long
1045
603
  ]
1046
604
  )
@@ -1056,7 +614,7 @@ class SandboxStatusTests(unittest.TestCase):
1056
614
  )
1057
615
  with env:
1058
616
  with self.assertRaises(interface.SessionTeardownError):
1059
- with env.sandbox(session_id='session1') as sb:
617
+ with env.sandbox('session1') as sb:
1060
618
  sb.shell('echo "hello"')
1061
619
  self.assertEqual(sb.status, interface.Sandbox.Status.OFFLINE)
1062
620
  self.assertEqual(
@@ -1064,34 +622,34 @@ class SandboxStatusTests(unittest.TestCase):
1064
622
  [
1065
623
  # pylint: disable=line-too-long
1066
624
  '[testing-env] environment started',
1067
- '[testing-env/test_image:0] shell: "feature1" setup',
625
+ '[testing-env/test_image:0@<idle>] shell: "feature1" setup',
1068
626
  '[testing-env/test_image:0/feature1] feature setup',
1069
- '[testing-env/test_image:0] shell: "feature2" setup',
627
+ '[testing-env/test_image:0@<idle>] shell: "feature2" setup',
1070
628
  '[testing-env/test_image:0/feature2] feature setup',
1071
629
  '[testing-env/test_image:0] created -> ready',
1072
630
  '[testing-env/test_image:0] sandbox started',
1073
631
  '[testing-env/test_image:0] ready -> acquired',
1074
632
  '[testing-env/test_image:0] acquired -> setting_up',
1075
- '[testing-env/test_image:0/session1] shell: "feature1" setup session',
1076
- '[testing-env/test_image:0/feature1] feature setup session',
1077
- '[testing-env/test_image:0/session1] shell: "feature2" setup session',
1078
- '[testing-env/test_image:0/feature2] feature setup session',
633
+ '[testing-env/test_image:0@session1] shell: "feature1" setup session',
634
+ '[testing-env/test_image:0/feature1@session1] feature setup session',
635
+ '[testing-env/test_image:0@session1] shell: "feature2" setup session',
636
+ '[testing-env/test_image:0/feature2@session1] feature setup session',
1079
637
  '[testing-env/test_image:0] setting_up -> in_session',
1080
638
  "[testing-env/test_image:0] session 'session1' started",
1081
- '[testing-env/test_image:0/session1] shell: echo "hello"',
639
+ '[testing-env/test_image:0@session1] shell: echo "hello"',
1082
640
  '[testing-env/test_image:0] in_session -> exiting_session',
1083
- '[testing-env/test_image:0/feature1] feature teardown session with ValueError', # pylint: disable=line-too-long
1084
- '[testing-env/test_image:0/session1] shell: "feature2" teardown session',
1085
- '[testing-env/test_image:0/feature2] feature teardown session',
641
+ '[testing-env/test_image:0/feature1@session1] feature teardown session with ValueError',
642
+ '[testing-env/test_image:0@session1] shell: "feature2" teardown session',
643
+ '[testing-env/test_image:0/feature2@session1] feature teardown session',
1086
644
  "[testing-env/test_image:0] session 'session1' ended",
1087
645
  '[testing-env/test_image:0] exiting_session -> acquired',
1088
646
  '[testing-env/test_image:0] acquired -> shutting_down',
1089
- '[testing-env/test_image:0] shell: "feature1" teardown',
647
+ '[testing-env/test_image:0@<idle>] shell: "feature1" teardown',
1090
648
  '[testing-env/test_image:0/feature1] feature teardown',
1091
- '[testing-env/test_image:0] shell: "feature2" teardown',
649
+ '[testing-env/test_image:0@<idle>] shell: "feature2" teardown',
1092
650
  '[testing-env/test_image:0/feature2] feature teardown',
1093
651
  '[testing-env/test_image:0] shutting_down -> offline',
1094
- '[testing-env/test_image:0] sandbox shutdown'
652
+ '[testing-env/test_image:0] sandbox shutdown',
1095
653
  # pylint: enable=line-too-long
1096
654
  ]
1097
655
  )
@@ -1106,7 +664,7 @@ class SandboxStatusTests(unittest.TestCase):
1106
664
  },
1107
665
  )
1108
666
  with env:
1109
- with env.sandbox(session_id='session1') as sb:
667
+ with env.sandbox('session1') as sb:
1110
668
  sb.shell('echo "hello"')
1111
669
  self.assertEqual(len(sb.state_errors), 1)
1112
670
  self.assertEqual(sb.status, interface.Sandbox.Status.OFFLINE)
@@ -1115,34 +673,34 @@ class SandboxStatusTests(unittest.TestCase):
1115
673
  [
1116
674
  # pylint: disable=line-too-long
1117
675
  '[testing-env] environment started',
1118
- '[testing-env/test_image:0] shell: "feature1" setup',
676
+ '[testing-env/test_image:0@<idle>] shell: "feature1" setup',
1119
677
  '[testing-env/test_image:0/feature1] feature setup',
1120
- '[testing-env/test_image:0] shell: "feature2" setup',
678
+ '[testing-env/test_image:0@<idle>] shell: "feature2" setup',
1121
679
  '[testing-env/test_image:0/feature2] feature setup',
1122
680
  '[testing-env/test_image:0] created -> ready',
1123
681
  '[testing-env/test_image:0] sandbox started',
1124
682
  '[testing-env/test_image:0] ready -> acquired',
1125
683
  '[testing-env/test_image:0] acquired -> setting_up',
1126
- '[testing-env/test_image:0/session1] shell: "feature1" setup session',
1127
- '[testing-env/test_image:0/feature1] feature setup session',
1128
- '[testing-env/test_image:0/session1] shell: "feature2" setup session',
1129
- '[testing-env/test_image:0/feature2] feature setup session',
684
+ '[testing-env/test_image:0@session1] shell: "feature1" setup session',
685
+ '[testing-env/test_image:0/feature1@session1] feature setup session',
686
+ '[testing-env/test_image:0@session1] shell: "feature2" setup session',
687
+ '[testing-env/test_image:0/feature2@session1] feature setup session',
1130
688
  '[testing-env/test_image:0] setting_up -> in_session',
1131
689
  "[testing-env/test_image:0] session 'session1' started",
1132
- '[testing-env/test_image:0/session1] shell: echo "hello"',
690
+ '[testing-env/test_image:0@session1] shell: echo "hello"',
1133
691
  '[testing-env/test_image:0] in_session -> exiting_session',
1134
- '[testing-env/test_image:0/feature1] feature teardown session with SandboxStateError', # pylint: disable=line-too-long
1135
- '[testing-env/test_image:0/session1] shell: "feature2" teardown session',
1136
- '[testing-env/test_image:0/feature2] feature teardown session',
692
+ '[testing-env/test_image:0/feature1@session1] feature teardown session with SandboxStateError',
693
+ '[testing-env/test_image:0@session1] shell: "feature2" teardown session',
694
+ '[testing-env/test_image:0/feature2@session1] feature teardown session',
1137
695
  "[testing-env/test_image:0] session 'session1' ended with SandboxStateError",
1138
696
  '[testing-env/test_image:0] exiting_session -> acquired',
1139
697
  '[testing-env/test_image:0] acquired -> shutting_down',
1140
- '[testing-env/test_image:0] shell: "feature1" teardown',
698
+ '[testing-env/test_image:0@<idle>] shell: "feature1" teardown',
1141
699
  '[testing-env/test_image:0/feature1] feature teardown',
1142
- '[testing-env/test_image:0] shell: "feature2" teardown',
700
+ '[testing-env/test_image:0@<idle>] shell: "feature2" teardown',
1143
701
  '[testing-env/test_image:0/feature2] feature teardown',
1144
702
  '[testing-env/test_image:0] shutting_down -> offline',
1145
- '[testing-env/test_image:0] sandbox shutdown'
703
+ '[testing-env/test_image:0] sandbox shutdown',
1146
704
  # pylint: enable=line-too-long
1147
705
  ]
1148
706
  )
@@ -1157,39 +715,39 @@ class SandboxStatusTests(unittest.TestCase):
1157
715
  },
1158
716
  )
1159
717
  with env:
1160
- with env.sandbox(session_id='session1') as sb:
718
+ with env.sandbox('session1') as sb:
1161
719
  sb.shell('echo "hello"')
1162
720
  self.assertEqual(
1163
721
  self.event_handler.logs,
1164
722
  [
1165
723
  # pylint: disable=line-too-long
1166
724
  '[testing-env] environment started',
1167
- '[testing-env/test_image:0] shell: "feature1" setup',
725
+ '[testing-env/test_image:0@<idle>] shell: "feature1" setup',
1168
726
  '[testing-env/test_image:0/feature1] feature setup',
1169
- '[testing-env/test_image:0] shell: "feature2" setup',
727
+ '[testing-env/test_image:0@<idle>] shell: "feature2" setup',
1170
728
  '[testing-env/test_image:0/feature2] feature setup',
1171
729
  '[testing-env/test_image:0] created -> ready',
1172
730
  '[testing-env/test_image:0] sandbox started',
1173
731
  '[testing-env/test_image:0] ready -> acquired',
1174
732
  '[testing-env/test_image:0] acquired -> setting_up',
1175
- '[testing-env/test_image:0/session1] shell: "feature1" setup session',
1176
- '[testing-env/test_image:0/feature1] feature setup session',
1177
- '[testing-env/test_image:0/session1] shell: "feature2" setup session',
1178
- '[testing-env/test_image:0/feature2] feature setup session',
733
+ '[testing-env/test_image:0@session1] shell: "feature1" setup session',
734
+ '[testing-env/test_image:0/feature1@session1] feature setup session',
735
+ '[testing-env/test_image:0@session1] shell: "feature2" setup session',
736
+ '[testing-env/test_image:0/feature2@session1] feature setup session',
1179
737
  '[testing-env/test_image:0] setting_up -> in_session',
1180
738
  "[testing-env/test_image:0] session 'session1' started",
1181
- '[testing-env/test_image:0/session1] shell: echo "hello"',
739
+ '[testing-env/test_image:0@session1] shell: echo "hello"',
1182
740
  '[testing-env/test_image:0] in_session -> exiting_session',
1183
- '[testing-env/test_image:0/session1] shell: "feature1" teardown session',
1184
- '[testing-env/test_image:0/feature1] feature teardown session',
1185
- '[testing-env/test_image:0/session1] shell: "feature2" teardown session',
1186
- '[testing-env/test_image:0/feature2] feature teardown session',
741
+ '[testing-env/test_image:0@session1] shell: "feature1" teardown session',
742
+ '[testing-env/test_image:0/feature1@session1] feature teardown session',
743
+ '[testing-env/test_image:0@session1] shell: "feature2" teardown session',
744
+ '[testing-env/test_image:0/feature2@session1] feature teardown session',
1187
745
  "[testing-env/test_image:0] session 'session1' ended",
1188
746
  '[testing-env/test_image:0] exiting_session -> acquired',
1189
747
  '[testing-env/test_image:0] acquired -> shutting_down',
1190
- '[testing-env/test_image:0] shell: "feature1" teardown',
748
+ '[testing-env/test_image:0@<idle>] shell: "feature1" teardown',
1191
749
  '[testing-env/test_image:0/feature1] feature teardown',
1192
- '[testing-env/test_image:0] shell: "feature2" teardown',
750
+ '[testing-env/test_image:0@<idle>] shell: "feature2" teardown',
1193
751
  '[testing-env/test_image:0/feature2] feature teardown',
1194
752
  '[testing-env/test_image:0] shutting_down -> offline',
1195
753
  '[testing-env/test_image:0] sandbox shutdown'
@@ -1205,7 +763,7 @@ class SandboxStatusTests(unittest.TestCase):
1205
763
  },
1206
764
  )
1207
765
  with env:
1208
- with env.sandbox(session_id='session1') as sb:
766
+ with env.sandbox('session1') as sb:
1209
767
  with self.assertRaises(ValueError):
1210
768
  sb.shell('echo foo', raise_error=ValueError)
1211
769
  self.assertEqual(len(sb.state_errors), 0)
@@ -1217,10 +775,10 @@ class SandboxStatusTests(unittest.TestCase):
1217
775
  self.event_handler.logs,
1218
776
  [
1219
777
  # pylint: disable=line-too-long
1220
- '[testing-env/test_image:0:0] shell: "feature1" setup',
778
+ '[testing-env/test_image:0:0@<idle>] shell: "feature1" setup',
1221
779
  '[testing-env/test_image:0:0/feature1] feature setup',
1222
- '[testing-env/test_image:0:0] shell: "feature1" setup session',
1223
- '[testing-env/test_image:0:0/feature1] feature setup session',
780
+ '[testing-env/test_image:0:0@<idle>] shell: "feature1" setup session',
781
+ '[testing-env/test_image:0:0/feature1@<idle>] feature setup session',
1224
782
  '[testing-env/test_image:0:0] created -> ready',
1225
783
  '[testing-env/test_image:0:0] sandbox started',
1226
784
  '[testing-env] environment started',
@@ -1228,15 +786,15 @@ class SandboxStatusTests(unittest.TestCase):
1228
786
  '[testing-env/test_image:0:0] acquired -> setting_up',
1229
787
  '[testing-env/test_image:0:0] setting_up -> in_session',
1230
788
  "[testing-env/test_image:0:0] session 'session1' started",
1231
- '[testing-env/test_image:0:0/session1] shell: echo foo with ValueError',
1232
- '[testing-env/test_image:0:0/session1] shell: echo bar',
789
+ '[testing-env/test_image:0:0@session1] shell: echo foo with ValueError',
790
+ '[testing-env/test_image:0:0@session1] shell: echo bar',
1233
791
  '[testing-env/test_image:0:0] in_session -> exiting_session',
1234
- '[testing-env/test_image:0:0/session1] shell: "feature1" teardown session',
1235
- '[testing-env/test_image:0:0/feature1] feature teardown session',
792
+ '[testing-env/test_image:0:0@session1] shell: "feature1" teardown session',
793
+ '[testing-env/test_image:0:0/feature1@session1] feature teardown session',
1236
794
  "[testing-env/test_image:0:0] session 'session1' ended",
1237
795
  '[testing-env/test_image:0:0] exiting_session -> setting_up',
1238
- '[testing-env/test_image:0:0] shell: "feature1" setup session',
1239
- '[testing-env/test_image:0:0/feature1] feature setup session',
796
+ '[testing-env/test_image:0:0@<idle>] shell: "feature1" setup session',
797
+ '[testing-env/test_image:0:0/feature1@<idle>] feature setup session',
1240
798
  '[testing-env/test_image:0:0] setting_up -> ready',
1241
799
  # pylint: enable=line-too-long
1242
800
  ]
@@ -1251,7 +809,7 @@ class SandboxStatusTests(unittest.TestCase):
1251
809
  )
1252
810
  with env:
1253
811
  with self.assertRaises(interface.SandboxStateError):
1254
- with env.sandbox(session_id='session1') as sb:
812
+ with env.sandbox('session1') as sb:
1255
813
  sb.shell('echo foo', raise_error=RuntimeError)
1256
814
  self.assertEqual(len(sb.state_errors), 1)
1257
815
  self.assertEqual(sb.status, interface.Sandbox.Status.OFFLINE)
@@ -1259,10 +817,10 @@ class SandboxStatusTests(unittest.TestCase):
1259
817
  self.event_handler.logs,
1260
818
  [
1261
819
  # pylint: disable=line-too-long
1262
- '[testing-env/test_image:0:0] shell: "feature1" setup',
820
+ '[testing-env/test_image:0:0@<idle>] shell: "feature1" setup',
1263
821
  '[testing-env/test_image:0:0/feature1] feature setup',
1264
- '[testing-env/test_image:0:0] shell: "feature1" setup session',
1265
- '[testing-env/test_image:0:0/feature1] feature setup session',
822
+ '[testing-env/test_image:0:0@<idle>] shell: "feature1" setup session',
823
+ '[testing-env/test_image:0:0/feature1@<idle>] feature setup session',
1266
824
  '[testing-env/test_image:0:0] created -> ready',
1267
825
  '[testing-env/test_image:0:0] sandbox started',
1268
826
  '[testing-env] environment started',
@@ -1270,14 +828,14 @@ class SandboxStatusTests(unittest.TestCase):
1270
828
  '[testing-env/test_image:0:0] acquired -> setting_up',
1271
829
  '[testing-env/test_image:0:0] setting_up -> in_session',
1272
830
  "[testing-env/test_image:0:0] session 'session1' started",
1273
- '[testing-env/test_image:0:0/session1] shell: echo foo with RuntimeError',
831
+ '[testing-env/test_image:0:0@session1] shell: echo foo with RuntimeError',
1274
832
  '[testing-env/test_image:0:0] in_session -> exiting_session',
1275
- '[testing-env/test_image:0:0/session1] shell: "feature1" teardown session',
1276
- '[testing-env/test_image:0:0/feature1] feature teardown session',
833
+ '[testing-env/test_image:0:0@session1] shell: "feature1" teardown session',
834
+ '[testing-env/test_image:0:0/feature1@session1] feature teardown session',
1277
835
  "[testing-env/test_image:0:0] session 'session1' ended with SandboxStateError",
1278
836
  '[testing-env/test_image:0:0] exiting_session -> acquired',
1279
837
  '[testing-env/test_image:0:0] acquired -> shutting_down',
1280
- '[testing-env/test_image:0:0] shell: "feature1" teardown',
838
+ '[testing-env/test_image:0:0@<idle>] shell: "feature1" teardown',
1281
839
  '[testing-env/test_image:0:0/feature1] feature teardown',
1282
840
  '[testing-env/test_image:0:0] shutting_down -> offline',
1283
841
  '[testing-env/test_image:0:0] sandbox shutdown',
@@ -1311,7 +869,7 @@ class SandboxActivityTests(unittest.TestCase):
1311
869
  sandbox_keepalive_interval=0,
1312
870
  )
1313
871
  with env:
1314
- with env.sandbox(session_id='session1') as sb:
872
+ with env.sandbox('session1') as sb:
1315
873
  sb.rebind(
1316
874
  simulate_ping_error=interface.SandboxStateError,
1317
875
  skip_notification=True
@@ -1328,10 +886,10 @@ class SandboxActivityTests(unittest.TestCase):
1328
886
  outage_grace_period=0,
1329
887
  outage_retry_interval=0.1,
1330
888
  sandbox_keepalive_interval=0,
1331
- event_handlers=[event_handler],
889
+ event_handler=event_handler,
1332
890
  )
1333
891
  with env:
1334
- with env.sandbox(session_id='session1') as sb:
892
+ with env.sandbox('session1') as sb:
1335
893
  self.assertEqual(len(env.sandbox_pool), 1)
1336
894
  self.assertEqual(sb.status, interface.Sandbox.Status.IN_SESSION)
1337
895
  self.assertEqual(sb.session_id, 'session1')
@@ -1351,22 +909,22 @@ class SandboxActivityTests(unittest.TestCase):
1351
909
  event_handler.logs,
1352
910
  [
1353
911
  # pylint: disable=line-too-long
1354
- '[testing-env/test_image:0:0] shell: "test_feature" setup',
912
+ '[testing-env/test_image:0:0@<idle>] shell: "test_feature" setup',
1355
913
  '[testing-env/test_image:0:0/test_feature] feature setup',
1356
- '[testing-env/test_image:0:0] shell: "test_feature" setup session',
914
+ '[testing-env/test_image:0:0@<idle>] shell: "test_feature" setup session',
1357
915
  '[testing-env/test_image:0:0] sandbox started',
1358
916
  '[testing-env] environment started',
1359
917
  "[testing-env/test_image:0:0] session 'session1' started",
1360
- '[testing-env/test_image:0:0/session1] shell: "test_feature" teardown session',
918
+ '[testing-env/test_image:0:0@session1] shell: "test_feature" teardown session',
1361
919
  "[testing-env/test_image:0:0] session 'session1' ended with SandboxStateError",
1362
- '[testing-env/test_image:0:0] shell: "test_feature" teardown',
920
+ '[testing-env/test_image:0:0@<idle>] shell: "test_feature" teardown',
1363
921
  '[testing-env/test_image:0:0/test_feature] feature teardown',
1364
922
  '[testing-env/test_image:0:0] sandbox shutdown',
1365
- '[testing-env/test_image:0:1] shell: "test_feature" setup',
923
+ '[testing-env/test_image:0:1@<idle>] shell: "test_feature" setup',
1366
924
  '[testing-env/test_image:0:1/test_feature] feature setup',
1367
- '[testing-env/test_image:0:1] shell: "test_feature" setup session',
925
+ '[testing-env/test_image:0:1@<idle>] shell: "test_feature" setup session',
1368
926
  '[testing-env/test_image:0:1] sandbox started',
1369
- '[testing-env/test_image:0:1] shell: "test_feature" teardown',
927
+ '[testing-env/test_image:0:1@<idle>] shell: "test_feature" teardown',
1370
928
  '[testing-env/test_image:0:1/test_feature] feature teardown',
1371
929
  '[testing-env/test_image:0:1] sandbox shutdown',
1372
930
  '[testing-env] environment shutdown'
@@ -1374,27 +932,6 @@ class SandboxActivityTests(unittest.TestCase):
1374
932
  ]
1375
933
  )
1376
934
 
1377
- def test_remove_event_handler(self):
1378
- env = TestingEnvironment(
1379
- features={'test_feature': TestingFeature(housekeep_interval=0)},
1380
- pool_size=1,
1381
- outage_grace_period=0,
1382
- outage_retry_interval=0,
1383
- sandbox_keepalive_interval=0,
1384
- )
1385
- event_handler = TestingEventHandler()
1386
- with env:
1387
- with env.sandbox(session_id='session1') as sb:
1388
- sb.add_event_handler(event_handler)
1389
- sb.shell('test_feature')
1390
- sb.remove_event_handler(event_handler)
1391
- events = list(event_handler.logs)
1392
- sb.wait_until_not(interface.Sandbox.Status.SETTING_UP)
1393
- self.assertGreater(len(events), 0)
1394
- with env.sandbox(session_id='session2') as sb:
1395
- sb.shell('test_feature')
1396
- self.assertEqual(len(events), len(event_handler.logs))
1397
-
1398
935
 
1399
936
  class SandboxServiceTests(unittest.TestCase):
1400
937
 
@@ -1408,13 +945,13 @@ class SandboxServiceTests(unittest.TestCase):
1408
945
  outage_grace_period=0,
1409
946
  outage_retry_interval=0,
1410
947
  sandbox_keepalive_interval=0,
1411
- event_handlers=[self.event_handler],
948
+ event_handler=self.event_handler,
1412
949
  random_seed=1,
1413
950
  )
1414
951
 
1415
952
  def test_service_call_activity_log(self):
1416
953
 
1417
- class CustomEventHandler(event_handler_base.EventHandler):
954
+ class CustomEventHandler(interface.EventHandler):
1418
955
 
1419
956
  def __init__(self):
1420
957
  self.calls = []
@@ -1422,9 +959,17 @@ class SandboxServiceTests(unittest.TestCase):
1422
959
  def on_sandbox_activity(
1423
960
  self,
1424
961
  name: str,
1425
- environment: interface.Environment,
1426
962
  sandbox: interface.Sandbox,
1427
- feature: interface.Feature | None,
963
+ session_id: str | None,
964
+ duration: float,
965
+ error: BaseException | None,
966
+ **kwargs: Any):
967
+ self.calls.append((session_id, name, kwargs))
968
+
969
+ def on_feature_activity(
970
+ self,
971
+ name: str,
972
+ feature: interface.Feature,
1428
973
  session_id: str | None,
1429
974
  duration: float,
1430
975
  error: BaseException | None,
@@ -1435,7 +980,7 @@ class SandboxServiceTests(unittest.TestCase):
1435
980
  env = TestingEnvironment(
1436
981
  features={'test_feature': TestingFeature()},
1437
982
  pool_size=0,
1438
- event_handlers=[event_handler],
983
+ event_handler=event_handler,
1439
984
  )
1440
985
  with env:
1441
986
  with env.test_feature(session_id='session1') as test_feature:
@@ -1453,7 +998,7 @@ class SandboxServiceTests(unittest.TestCase):
1453
998
 
1454
999
  def test_service_call_from_feature(self):
1455
1000
  with self.env:
1456
- with self.env.sandbox(session_id='session1') as sb:
1001
+ with self.env.sandbox('session1') as sb:
1457
1002
  self.assertEqual(sb.test_feature.num_shell_calls(), 2)
1458
1003
  self.assertEqual(sb.test_feature.num_shell_calls(), 2)
1459
1004
  self.assertEqual(
@@ -1461,19 +1006,19 @@ class SandboxServiceTests(unittest.TestCase):
1461
1006
  [
1462
1007
  # pylint: disable=line-too-long
1463
1008
  '[testing-env] environment started',
1464
- '[testing-env/test_image:0] shell: "test_feature" setup',
1009
+ '[testing-env/test_image:0@<idle>] shell: "test_feature" setup',
1465
1010
  '[testing-env/test_image:0/test_feature] feature setup',
1466
1011
  '[testing-env/test_image:0] sandbox started',
1467
- '[testing-env/test_image:0/session1] shell: "test_feature" setup session',
1012
+ '[testing-env/test_image:0@session1] shell: "test_feature" setup session',
1468
1013
  "[testing-env/test_image:0] session 'session1' started",
1469
- '[testing-env/test_image:0/session1/test_feature] test_feature.num_shell_calls: None',
1470
- '[testing-env/test_image:0/session1/test_feature] test_feature.num_shell_calls: None',
1471
- '[testing-env/test_image:0/session1] shell: "test_feature" teardown session',
1014
+ '[testing-env/test_image:0/test_feature@session1] test_feature.num_shell_calls: None',
1015
+ '[testing-env/test_image:0/test_feature@session1] test_feature.num_shell_calls: None',
1016
+ '[testing-env/test_image:0@session1] shell: "test_feature" teardown session',
1472
1017
  "[testing-env/test_image:0] session 'session1' ended",
1473
- '[testing-env/test_image:0] shell: "test_feature" teardown',
1018
+ '[testing-env/test_image:0@<idle>] shell: "test_feature" teardown',
1474
1019
  '[testing-env/test_image:0/test_feature] feature teardown',
1475
1020
  '[testing-env/test_image:0] sandbox shutdown',
1476
- '[testing-env] environment shutdown'
1021
+ '[testing-env] environment shutdown',
1477
1022
  # pylint: enable=line-too-long
1478
1023
  ]
1479
1024
  )
@@ -1481,26 +1026,25 @@ class SandboxServiceTests(unittest.TestCase):
1481
1026
  def test_service_call_from_feature_with_error(self):
1482
1027
  with self.env:
1483
1028
  with self.assertRaises(interface.SandboxStateError):
1484
- with self.env.sandbox(session_id='session1') as sb:
1029
+ with self.env.sandbox('session1') as sb:
1485
1030
  sb.test_feature.bad_shell_call()
1486
1031
  self.assertEqual(sb.status, interface.Sandbox.Status.OFFLINE)
1487
1032
  self.assertEqual(len(sb.state_errors), 1)
1488
-
1489
1033
  self.assertEqual(
1490
1034
  self.event_handler.logs,
1491
1035
  [
1492
1036
  # pylint: disable=line-too-long
1493
1037
  '[testing-env] environment started',
1494
- '[testing-env/test_image:0] shell: "test_feature" setup',
1038
+ '[testing-env/test_image:0@<idle>] shell: "test_feature" setup',
1495
1039
  '[testing-env/test_image:0/test_feature] feature setup',
1496
1040
  '[testing-env/test_image:0] sandbox started',
1497
- '[testing-env/test_image:0/session1] shell: "test_feature" setup session',
1041
+ '[testing-env/test_image:0@session1] shell: "test_feature" setup session',
1498
1042
  "[testing-env/test_image:0] session 'session1' started",
1499
- '[testing-env/test_image:0/session1] shell: bad command with RuntimeError',
1500
- '[testing-env/test_image:0/session1/test_feature] test_feature.bad_shell_call: None with SandboxStateError',
1501
- '[testing-env/test_image:0/session1] shell: "test_feature" teardown session',
1043
+ '[testing-env/test_image:0@session1] shell: bad command with RuntimeError',
1044
+ '[testing-env/test_image:0/test_feature@session1] test_feature.bad_shell_call: None with SandboxStateError',
1045
+ '[testing-env/test_image:0@session1] shell: "test_feature" teardown session',
1502
1046
  "[testing-env/test_image:0] session 'session1' ended with SandboxStateError",
1503
- '[testing-env/test_image:0] shell: "test_feature" teardown',
1047
+ '[testing-env/test_image:0@<idle>] shell: "test_feature" teardown',
1504
1048
  '[testing-env/test_image:0/test_feature] feature teardown',
1505
1049
  '[testing-env/test_image:0] sandbox shutdown',
1506
1050
  '[testing-env] environment shutdown'
@@ -1517,15 +1061,15 @@ class SandboxServiceTests(unittest.TestCase):
1517
1061
  [
1518
1062
  # pylint: disable=line-too-long
1519
1063
  '[testing-env] environment started',
1520
- '[testing-env/test_image:0] shell: "test_feature" setup',
1064
+ '[testing-env/test_image:0@<idle>] shell: "test_feature" setup',
1521
1065
  '[testing-env/test_image:0/test_feature] feature setup',
1522
1066
  '[testing-env/test_image:0] sandbox started',
1523
- '[testing-env/test_image:0/test_feature-session-2291d8c] shell: "test_feature" setup session',
1067
+ '[testing-env/test_image:0@test_feature-session-2291d8c] shell: "test_feature" setup session',
1524
1068
  "[testing-env/test_image:0] session 'test_feature-session-2291d8c' started",
1525
- '[testing-env/test_image:0/test_feature-session-2291d8c/test_feature] test_feature.num_shell_calls: None',
1526
- '[testing-env/test_image:0/test_feature-session-2291d8c] shell: "test_feature" teardown session',
1069
+ '[testing-env/test_image:0/test_feature@test_feature-session-2291d8c] test_feature.num_shell_calls: None',
1070
+ '[testing-env/test_image:0@test_feature-session-2291d8c] shell: "test_feature" teardown session',
1527
1071
  "[testing-env/test_image:0] session 'test_feature-session-2291d8c' ended",
1528
- '[testing-env/test_image:0] shell: "test_feature" teardown',
1072
+ '[testing-env/test_image:0@<idle>] shell: "test_feature" teardown',
1529
1073
  '[testing-env/test_image:0/test_feature] feature teardown',
1530
1074
  '[testing-env/test_image:0] sandbox shutdown',
1531
1075
  '[testing-env] environment shutdown'
@@ -1543,26 +1087,26 @@ class SandboxServiceTests(unittest.TestCase):
1543
1087
  [
1544
1088
  # pylint: disable=line-too-long
1545
1089
  '[testing-env] environment started',
1546
- '[testing-env/test_image:0] shell: "test_feature" setup',
1090
+ '[testing-env/test_image:0@<idle>] shell: "test_feature" setup',
1547
1091
  '[testing-env/test_image:0/test_feature] feature setup',
1548
1092
  '[testing-env/test_image:0] sandbox started',
1549
- '[testing-env/test_image:0/session1] shell: "test_feature" setup session',
1093
+ '[testing-env/test_image:0@session1] shell: "test_feature" setup session',
1550
1094
  "[testing-env/test_image:0] session 'session1' started",
1551
- '[testing-env/test_image:0/session1] shell: bad command with RuntimeError',
1552
- '[testing-env/test_image:0/session1/test_feature] test_feature.bad_shell_call: None with SandboxStateError',
1553
- '[testing-env/test_image:0/session1] shell: "test_feature" teardown session',
1095
+ '[testing-env/test_image:0@session1] shell: bad command with RuntimeError',
1096
+ '[testing-env/test_image:0/test_feature@session1] test_feature.bad_shell_call: None with SandboxStateError',
1097
+ '[testing-env/test_image:0@session1] shell: "test_feature" teardown session',
1554
1098
  "[testing-env/test_image:0] session 'session1' ended with SandboxStateError",
1555
- '[testing-env/test_image:0] shell: "test_feature" teardown',
1099
+ '[testing-env/test_image:0@<idle>] shell: "test_feature" teardown',
1556
1100
  '[testing-env/test_image:0/test_feature] feature teardown',
1557
1101
  '[testing-env/test_image:0] sandbox shutdown',
1558
- '[testing-env] environment shutdown'
1102
+ '[testing-env] environment shutdown',
1559
1103
  # pylint: enable=line-too-long
1560
1104
  ]
1561
1105
  )
1562
1106
 
1563
1107
  def test_service_context_manager_from_feature(self):
1564
1108
  with self.env:
1565
- with self.env.sandbox(session_id='session1') as sb:
1109
+ with self.env.sandbox('session1') as sb:
1566
1110
  with sb.test_feature.my_service() as service:
1567
1111
  service.do('hello')
1568
1112
  sb.shell('foo')
@@ -1572,19 +1116,19 @@ class SandboxServiceTests(unittest.TestCase):
1572
1116
  [
1573
1117
  # pylint: disable=line-too-long
1574
1118
  '[testing-env] environment started',
1575
- '[testing-env/test_image:0] shell: "test_feature" setup',
1119
+ '[testing-env/test_image:0@<idle>] shell: "test_feature" setup',
1576
1120
  '[testing-env/test_image:0/test_feature] feature setup',
1577
1121
  '[testing-env/test_image:0] sandbox started',
1578
- '[testing-env/test_image:0/session1] shell: "test_feature" setup session',
1122
+ '[testing-env/test_image:0@session1] shell: "test_feature" setup session',
1579
1123
  "[testing-env/test_image:0] session 'session1' started",
1580
- '[testing-env/test_image:0/session1] shell: hello',
1581
- '[testing-env/test_image:0/session1] shell: foo',
1582
- '[testing-env/test_image:0/session1] shell: "test_feature" teardown session',
1124
+ '[testing-env/test_image:0@session1] shell: hello',
1125
+ '[testing-env/test_image:0@session1] shell: foo',
1126
+ '[testing-env/test_image:0@session1] shell: "test_feature" teardown session',
1583
1127
  "[testing-env/test_image:0] session 'session1' ended",
1584
- '[testing-env/test_image:0] shell: "test_feature" teardown',
1128
+ '[testing-env/test_image:0@<idle>] shell: "test_feature" teardown',
1585
1129
  '[testing-env/test_image:0/test_feature] feature teardown',
1586
1130
  '[testing-env/test_image:0] sandbox shutdown',
1587
- '[testing-env] environment shutdown'
1131
+ '[testing-env] environment shutdown',
1588
1132
  # pylint: enable=line-too-long
1589
1133
  ]
1590
1134
  )
@@ -1592,7 +1136,7 @@ class SandboxServiceTests(unittest.TestCase):
1592
1136
  def test_service_context_manager_from_feature_with_error(self):
1593
1137
  with self.env:
1594
1138
  with self.assertRaises(interface.SandboxStateError):
1595
- with self.env.sandbox(session_id='session1') as sb:
1139
+ with self.env.sandbox('session1') as sb:
1596
1140
  with sb.test_feature.my_service() as service:
1597
1141
  service.do('hello', raise_error=interface.SandboxStateError)
1598
1142
  self.assertEqual(sb.status, interface.Sandbox.Status.OFFLINE)
@@ -1602,18 +1146,18 @@ class SandboxServiceTests(unittest.TestCase):
1602
1146
  [
1603
1147
  # pylint: disable=line-too-long
1604
1148
  '[testing-env] environment started',
1605
- '[testing-env/test_image:0] shell: "test_feature" setup',
1149
+ '[testing-env/test_image:0@<idle>] shell: "test_feature" setup',
1606
1150
  '[testing-env/test_image:0/test_feature] feature setup',
1607
1151
  '[testing-env/test_image:0] sandbox started',
1608
- '[testing-env/test_image:0/session1] shell: "test_feature" setup session',
1152
+ '[testing-env/test_image:0@session1] shell: "test_feature" setup session',
1609
1153
  "[testing-env/test_image:0] session 'session1' started",
1610
- '[testing-env/test_image:0/session1] shell: hello with SandboxStateError',
1611
- '[testing-env/test_image:0/session1] shell: "test_feature" teardown session',
1154
+ '[testing-env/test_image:0@session1] shell: hello with SandboxStateError',
1155
+ '[testing-env/test_image:0@session1] shell: "test_feature" teardown session',
1612
1156
  "[testing-env/test_image:0] session 'session1' ended with SandboxStateError",
1613
- '[testing-env/test_image:0] shell: "test_feature" teardown',
1157
+ '[testing-env/test_image:0@<idle>] shell: "test_feature" teardown',
1614
1158
  '[testing-env/test_image:0/test_feature] feature teardown',
1615
1159
  '[testing-env/test_image:0] sandbox shutdown',
1616
- '[testing-env] environment shutdown'
1160
+ '[testing-env] environment shutdown',
1617
1161
  # pylint: enable=line-too-long
1618
1162
  ]
1619
1163
  )
@@ -1632,29 +1176,29 @@ class SandboxServiceTests(unittest.TestCase):
1632
1176
  [
1633
1177
  # pylint: disable=line-too-long
1634
1178
  '[testing-env] environment started',
1635
- '[testing-env/test_image:0] shell: "test_feature" setup',
1179
+ '[testing-env/test_image:0@<idle>] shell: "test_feature" setup',
1636
1180
  '[testing-env/test_image:0/test_feature] feature setup',
1637
1181
  '[testing-env/test_image:0] sandbox started',
1638
- '[testing-env/test_image:0/session1] shell: "test_feature" setup session',
1182
+ '[testing-env/test_image:0@session1] shell: "test_feature" setup session',
1639
1183
  "[testing-env/test_image:0] session 'session1' started",
1640
- '[testing-env/test_image:0/session1] shell: foo',
1641
- '[testing-env/test_image:0/session1] shell: "test_feature" teardown session',
1184
+ '[testing-env/test_image:0@session1] shell: foo',
1185
+ '[testing-env/test_image:0@session1] shell: "test_feature" teardown session',
1642
1186
  "[testing-env/test_image:0] session 'session1' ended",
1643
- '[testing-env/test_image:0] shell: "test_feature" teardown',
1187
+ '[testing-env/test_image:0@<idle>] shell: "test_feature" teardown',
1644
1188
  '[testing-env/test_image:0/test_feature] feature teardown',
1645
1189
  '[testing-env/test_image:0] sandbox shutdown',
1646
- '[testing-env/test_image:1] shell: "test_feature" setup',
1190
+ '[testing-env/test_image:1@<idle>] shell: "test_feature" setup',
1647
1191
  '[testing-env/test_image:1/test_feature] feature setup',
1648
1192
  '[testing-env/test_image:1] sandbox started',
1649
- '[testing-env/test_image:1/test_feature-session-2291d8c] shell: "test_feature" setup session',
1193
+ '[testing-env/test_image:1@test_feature-session-2291d8c] shell: "test_feature" setup session',
1650
1194
  "[testing-env/test_image:1] session 'test_feature-session-2291d8c' started",
1651
- '[testing-env/test_image:1/test_feature-session-2291d8c] shell: bar',
1652
- '[testing-env/test_image:1/test_feature-session-2291d8c] shell: "test_feature" teardown session',
1195
+ '[testing-env/test_image:1@test_feature-session-2291d8c] shell: bar',
1196
+ '[testing-env/test_image:1@test_feature-session-2291d8c] shell: "test_feature" teardown session',
1653
1197
  "[testing-env/test_image:1] session 'test_feature-session-2291d8c' ended",
1654
- '[testing-env/test_image:1] shell: "test_feature" teardown',
1198
+ '[testing-env/test_image:1@<idle>] shell: "test_feature" teardown',
1655
1199
  '[testing-env/test_image:1/test_feature] feature teardown',
1656
1200
  '[testing-env/test_image:1] sandbox shutdown',
1657
- '[testing-env] environment shutdown'
1201
+ '[testing-env] environment shutdown',
1658
1202
  # pylint: enable=line-too-long
1659
1203
  ]
1660
1204
  )
@@ -1670,18 +1214,18 @@ class SandboxServiceTests(unittest.TestCase):
1670
1214
  [
1671
1215
  # pylint: disable=line-too-long
1672
1216
  '[testing-env] environment started',
1673
- '[testing-env/test_image:0] shell: "test_feature" setup',
1217
+ '[testing-env/test_image:0@<idle>] shell: "test_feature" setup',
1674
1218
  '[testing-env/test_image:0/test_feature] feature setup',
1675
1219
  '[testing-env/test_image:0] sandbox started',
1676
- '[testing-env/test_image:0/test_feature-session-2291d8c] shell: "test_feature" setup session',
1220
+ '[testing-env/test_image:0@test_feature-session-2291d8c] shell: "test_feature" setup session',
1677
1221
  "[testing-env/test_image:0] session 'test_feature-session-2291d8c' started",
1678
- '[testing-env/test_image:0/test_feature-session-2291d8c] shell: hello with SandboxStateError',
1679
- '[testing-env/test_image:0/test_feature-session-2291d8c] shell: "test_feature" teardown session',
1222
+ '[testing-env/test_image:0@test_feature-session-2291d8c] shell: hello with SandboxStateError',
1223
+ '[testing-env/test_image:0@test_feature-session-2291d8c] shell: "test_feature" teardown session',
1680
1224
  "[testing-env/test_image:0] session 'test_feature-session-2291d8c' ended with SandboxStateError",
1681
- '[testing-env/test_image:0] shell: "test_feature" teardown',
1225
+ '[testing-env/test_image:0@<idle>] shell: "test_feature" teardown',
1682
1226
  '[testing-env/test_image:0/test_feature] feature teardown',
1683
1227
  '[testing-env/test_image:0] sandbox shutdown',
1684
- '[testing-env] environment shutdown'
1228
+ '[testing-env] environment shutdown',
1685
1229
  # pylint: enable=line-too-long
1686
1230
  ]
1687
1231
  )