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
|
import os
import yaml
def install_vmadm(ctx):
runcmd_prepend_to_path = globals()["runcmd_prepend_to_path"]
srcdir = globals()["srcdir"]
runcmd_prepend_to_path(ctx, os.path.join(srcdir, "target", "debug"))
# Set permissions on the datadir and its parent. They are 0o700 by default,
# which means that the libvirt daemon can't access the virtual machine
# image we create.
os.chmod(".", 0o711)
os.chmod("..", 0o711)
# Create .ssh directory, so that the scenario can put files there later.
# This can be removed once the Subplot lib/files library creates
# directories.
os.mkdir(".ssh")
def create_vm(ctx, filename=None):
runcmd_run = globals()["runcmd_run"]
runcmd_exit_code_is_zero = globals()["runcmd_exit_code_is_zero"]
with open(filename) as f:
spec = yaml.load(f)
ctx["spec"] = spec
runcmd_run(ctx, ["vmadm", "new", filename])
runcmd_exit_code_is_zero(ctx)
def delete_vm(ctx, filename=None):
runcmd_run = globals()["runcmd_run"]
runcmd_exit_code_is_zero = globals()["runcmd_exit_code_is_zero"]
name = ctx["spec"]["name"]
runcmd_run(ctx, ["vmadm", "delete", name])
runcmd_exit_code_is_zero(ctx)
def run_hostname_over_ssh(ctx, config=None, target=None, args=None):
runcmd_run = globals()["runcmd_run"]
runcmd_exit_code_is_zero = globals()["runcmd_exit_code_is_zero"]
# Fix permissions for .ssh and its contents.
runcmd_run(ctx, ["chmod", "-R", "u=rwX,go=", ".ssh"])
runcmd_run(ctx, ["ssh", "-F", config, target] + args.split())
runcmd_exit_code_is_zero(ctx)
|