7 from juju
.controller
import Controller
8 from juju
.client
.connection
import JujuData
11 def is_bootstrapped():
12 result
= subprocess
.run(['juju', 'switch'], stdout
=subprocess
.PIPE
)
14 result
.returncode
== 0 and
15 len(result
.stdout
.decode().strip()) > 0)
17 bootstrapped
= pytest
.mark
.skipif(
18 not is_bootstrapped(),
19 reason
='bootstrapped Juju environment required')
24 self
.controller
= None
27 async def __aenter__(self
):
28 self
.controller
= Controller()
29 await self
.controller
.connect_current()
31 model_name
= 'model-{}'.format(uuid
.uuid4())
32 self
.model
= await self
.controller
.add_model(model_name
)
34 # Ensure that we connect to the new model by default. This also
35 # prevents failures if test was started with no current model.
36 self
._patch
_cm
= mock
.patch
.object(JujuData
, 'current_model',
37 return_value
=model_name
)
38 self
._patch
_cm
.start()
42 async def __aexit__(self
, exc_type
, exc
, tb
):
44 await self
.model
.disconnect()
45 await self
.controller
.destroy_model(self
.model
.info
.uuid
)
46 await self
.controller
.disconnect()