Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
fuss-manager
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
32
Issues
32
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
FUSS
fuss-manager
Commits
2f63ea2a
Commit
2f63ea2a
authored
Aug 12, 2020
by
Elena Grandi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
flake8
parent
6672dfed
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
78 additions
and
30 deletions
+78
-30
test_network/base.py
test_network/base.py
+11
-2
test_network/domain.py
test_network/domain.py
+8
-6
test_network/image.py
test_network/image.py
+18
-5
test_network/master_image.py
test_network/master_image.py
+29
-12
test_network/storage.py
test_network/storage.py
+12
-5
No files found.
test_network/base.py
View file @
2f63ea2a
...
...
@@ -8,6 +8,7 @@ class Component:
"""
Lazily instantiated wrapper for a libvirt object
"""
def
__init__
(
self
,
system
,
name
):
self
.
system
=
system
self
.
name
=
name
...
...
@@ -20,7 +21,11 @@ class Component:
This function should be idempotent with regards to side effects on the
system.
"""
raise
NotImplementedError
(
"{}.start called but not implemented"
.
format
(
self
.
__class__
.
__name__
))
raise
NotImplementedError
(
"{}.start called but not implemented"
.
format
(
self
.
__class__
.
__name__
)
)
def
shutdown
(
self
):
"""
...
...
@@ -29,7 +34,11 @@ class Component:
This function should be idempotent with regards to side effects on the
system.
"""
raise
NotImplementedError
(
"{}.shutdown called but not implemented"
.
format
(
self
.
__class__
.
__name__
))
raise
NotImplementedError
(
"{}.shutdown called but not implemented"
.
format
(
self
.
__class__
.
__name__
)
)
def
get
(
self
):
"""
...
...
test_network/domain.py
View file @
2f63ea2a
...
...
@@ -16,7 +16,10 @@ class Domain(Component):
self
.
base
=
base
if
mac
is
None
:
mac
=
"02:00:00:{:02x}:{:02x}:{:02x}"
.
format
(
random
.
randint
(
0
,
255
),
random
.
randint
(
0
,
255
),
random
.
randint
(
0
,
255
))
random
.
randint
(
0
,
255
),
random
.
randint
(
0
,
255
),
random
.
randint
(
0
,
255
),
)
self
.
mac
=
mac
if
ip
is
None
:
# This is a convenience fallback with works for one machine or two,
...
...
@@ -24,9 +27,8 @@ class Domain(Component):
ip
=
"192.168.123.{:d}"
.
format
(
random
.
randint
(
2
,
254
))
self
.
ip
=
ip
self
.
domain_xml
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"provision"
,
base
+
".xml"
)
os
.
path
.
dirname
(
__file__
),
"provision"
,
base
+
".xml"
)
self
.
_image
=
None
@
property
...
...
@@ -77,12 +79,12 @@ class Domain(Component):
# virt-install --connect qemu:///system --ram 1024 \
# -n $NAME --os-type=linux --os-variant=debian9 \
# --network network=fuss_manager_test \
# --disk vol=fuss_manager_disks/$NAME.qcow2,device=disk,format=qcow2 \
# --disk vol=fuss_manager_disks/$NAME.qcow2,device=disk,format=qcow2 \
# noqa: E501
# --vcpus=1 --vnc --import
# virt-install --dry-run --print-xml --connect qemu:///system
# --ram 1024 -n fuss_manager_vm1 --os-type=linux --os-variant=debian9
# --network network=fuss_manager_test --disk vol=fuss_manager_disks/test.qcow2,device=disk,format=qcow2
# --network network=fuss_manager_test --disk vol=fuss_manager_disks/test.qcow2,device=disk,format=qcow2
# noqa: E501
# --vcpus=1 --vnc --import
with
io
.
StringIO
()
as
fd
:
...
...
test_network/image.py
View file @
2f63ea2a
...
...
@@ -10,7 +10,11 @@ class Image(Component):
def
__init__
(
self
,
system
,
name
,
base
):
super
().
__init__
(
system
,
name
)
self
.
base
=
base
self
.
pathname
=
os
.
path
.
abspath
(
os
.
path
.
join
(
self
.
system
.
storage_root
,
"images"
,
self
.
name
+
".qcow2"
))
self
.
pathname
=
os
.
path
.
abspath
(
os
.
path
.
join
(
self
.
system
.
storage_root
,
"images"
,
self
.
name
+
".qcow2"
)
)
def
start
(
self
):
src
=
self
.
system
.
master_image
(
self
.
base
)
...
...
@@ -21,10 +25,19 @@ class Image(Component):
# Clone a sandbox machine. See https://stackoverflow.com/a/26938505
log
.
info
(
"Creating %s based on %s"
,
self
.
pathname
,
src
)
subprocess
.
run
([
"qemu-img"
,
"create"
,
"-f"
,
"qcow2"
,
"-o"
,
"backing_file="
+
src
,
self
.
pathname
],
stdout
=
subprocess
.
DEVNULL
,
check
=
True
)
subprocess
.
run
(
[
"qemu-img"
,
"create"
,
"-f"
,
"qcow2"
,
"-o"
,
"backing_file="
+
src
,
self
.
pathname
,
],
stdout
=
subprocess
.
DEVNULL
,
check
=
True
,
)
# virsh -c qemu:///system pool-refresh fuss_manager_disks
self
.
system
.
storage
.
refresh
(
0
)
...
...
test_network/master_image.py
View file @
2f63ea2a
...
...
@@ -10,13 +10,17 @@ class MasterImage(Component):
"""
Wrap a path to a base image
"""
def
__init__
(
self
,
system
,
name
):
super
().
__init__
(
system
,
name
)
self
.
pathname
=
os
.
path
.
abspath
(
os
.
path
.
join
(
self
.
system
.
storage_root
,
"master"
,
self
.
name
+
".qcow2"
))
self
.
pathname
=
os
.
path
.
abspath
(
os
.
path
.
join
(
self
.
system
.
storage_root
,
"master"
,
self
.
name
+
".qcow2"
)
)
self
.
provision_script
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"provision"
,
self
.
name
+
".sh"
)
os
.
path
.
dirname
(
__file__
),
"provision"
,
self
.
name
+
".sh"
)
self
.
ssh_public_key
=
None
for
path
in
(
"~/.ssh/id_rsa.pub"
,):
...
...
@@ -35,25 +39,38 @@ class MasterImage(Component):
if
pathname
is
None
:
os
.
makedirs
(
os
.
path
.
dirname
(
self
.
pathname
),
exist_ok
=
True
)
# virt-builder debian-9 --format qcow2 -o /tmp/fuss-manager-test-disks/master/debian-9.qcow2
# --root-password password:root --ssh-inject root:file:/home/enrico/.ssh/id_rsa.pub
# virt-builder debian-9 --format qcow2 \
# -o /tmp/fuss-manager-test-disks/master/debian-9.qcow2 \
# --root-password password:root \
# --ssh-inject root:file:/home/enrico/.ssh/id_rsa.pub
# --firstboot provision.sh
log
.
info
(
"Building master image %s as %s"
,
self
.
name
,
self
.
pathname
)
log
.
info
(
"Building master image %s as %s"
,
self
.
name
,
self
.
pathname
)
cmd
=
[
"virt-builder"
,
self
.
name
,
"--format"
,
"qcow2"
,
"-o"
,
self
.
pathname
,
"--root-password"
,
"password:root"
,
"--format"
,
"qcow2"
,
"-o"
,
self
.
pathname
,
"--root-password"
,
"password:root"
,
]
if
self
.
ssh_public_key
:
log
.
info
(
" using ssh public key %s"
,
self
.
ssh_public_key
)
cmd
+=
[
"--ssh-inject"
,
"root:file:"
+
self
.
ssh_public_key
]
if
os
.
path
.
exists
(
self
.
provision_script
):
log
.
info
(
" using provisioning script %s"
,
self
.
provision_script
)
log
.
info
(
" using provisioning script %s"
,
self
.
provision_script
)
cmd
+=
[
"--firstboot"
,
self
.
provision_script
]
else
:
log
.
info
(
" no provisioning script found for %s (%s)"
,
self
.
name
,
self
.
provision_script
)
log
.
info
(
" no provisioning script found for %s (%s)"
,
self
.
name
,
self
.
provision_script
,
)
subprocess
.
run
(
cmd
,
check
=
True
)
return
self
.
pathname
...
...
test_network/storage.py
View file @
2f63ea2a
...
...
@@ -32,12 +32,15 @@ class Storage(Component):
"""
storage
=
self
.
lookup
()
if
storage
is
None
:
# virsh -c qemu:///system pool-define-as fuss_manager_disks dir --target {{self.root}}/images
# virsh -c qemu:///system pool-define-as fuss_manager_disks \
# dir --target {{self.root}}/images
images_dir
=
os
.
path
.
join
(
self
.
system
.
storage_root
,
"images"
)
os
.
makedirs
(
images_dir
,
exist_ok
=
True
)
# TODO: check that things are readable/writable by the group libvirt (how?)
# TIL: namei -l `readlink -f .` which is nice, but still not useful enough
# TODO: check that things are readable/writable by the group
# libvirt (how?)
# TIL: namei -l `readlink -f .` which is nice, but still not
# useful enough
# master_dir = os.path.join(self.root, "master")
# images_dir = os.path.join(self.root, "images")
...
...
@@ -49,9 +52,13 @@ class Storage(Component):
<path>{path}</path>
</target>
</pool>
"""
.
format
(
name
=
self
.
name
,
path
=
images_dir
)
"""
.
format
(
name
=
self
.
name
,
path
=
images_dir
)
log
.
info
(
"Defining storage pool %s on %s"
,
self
.
name
,
images_dir
)
storage
=
self
.
system
.
connection
.
storagePoolDefineXML
(
storage_cfg
,
0
)
storage
=
self
.
system
.
connection
.
storagePoolDefineXML
(
storage_cfg
,
0
)
# virsh -c qemu:///system pool-start fuss_manager_disks
if
not
storage
.
isActive
():
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment