This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New: Add guests - Alpine, Centos, Fedora, Gentoo, OpenSUSE, Oracle. C…
…loses #29. (#36) 1. Also fixed the regex for detecting Linux distro. 2. Replaced `bash` as `su -m root` in `lxdock shell`, to use the default shell of the Linux distro.
- Loading branch information
1 parent
c23f588
commit 6e7ca8e
Showing
17 changed files
with
220 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from .base import Guest | ||
|
||
|
||
class AlpineGuest(Guest): | ||
""" This guest can provision Alpine containers. """ | ||
|
||
name = 'alpine' | ||
barebones_packages = [ | ||
'openssh', | ||
'python', | ||
] | ||
|
||
def install_barebones_packages(self): | ||
""" Installs packages when the guest is first provisionned. """ | ||
self.run(['apk', 'update']) | ||
self.run(['apk', 'add'] + self.barebones_packages) | ||
self.run(['rc-update', 'add', 'sshd']) | ||
self.run(['/etc/init.d/sshd', 'start']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from .base import Guest | ||
|
||
|
||
class CentosGuest(Guest): | ||
""" This guest can provision Centos containers. """ | ||
|
||
name = 'centos' | ||
barebones_packages = [ | ||
'openssh-server', | ||
'python', | ||
] | ||
|
||
def install_barebones_packages(self): | ||
""" Installs packages when the guest is first provisionned. """ | ||
self.run(['yum', '-y', 'install'] + self.barebones_packages) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from .base import Guest | ||
|
||
|
||
class FedoraGuest(Guest): | ||
""" This guest can provision Fedora containers. """ | ||
|
||
name = 'fedora' | ||
barebones_packages = [ | ||
'openssh-server', | ||
'python3', | ||
] | ||
|
||
def install_barebones_packages(self): | ||
""" Installs packages when the guest is first provisionned. """ | ||
self.run(['dnf', '-y', 'install', ] + self.barebones_packages) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from .base import Guest | ||
|
||
|
||
class GentooGuest(Guest): | ||
""" This guest can provision Gentoo containers. """ | ||
|
||
name = 'gentoo' | ||
barebones_packages = [ | ||
'net-misc/openssh', | ||
'dev-lang/python', | ||
] | ||
|
||
def install_barebones_packages(self): | ||
""" Installs packages when the guest is first provisionned. """ | ||
# Ensure that we have this Gentoo helper toolkit. | ||
# It contains "equery" that can check which package has been installed. | ||
self.run(['emerge', 'app-portage/gentoolkit']) | ||
|
||
for p in self.barebones_packages: | ||
retcode = self.run(['equery', 'list', p]) | ||
if retcode != 0: # Not installed yet | ||
self.run(['emerge', p]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from .base import Guest | ||
|
||
|
||
class OpenSUSEGuest(Guest): | ||
""" This guest can provision openSUSE containers. """ | ||
|
||
name = 'opensuse' | ||
barebones_packages = [ | ||
'openSSH', | ||
'python3-base', | ||
] | ||
|
||
def install_barebones_packages(self): | ||
""" Installs packages when the guest is first provisionned. """ | ||
self.run(['zypper', '--non-interactive', 'install', ] + self.barebones_packages) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from .base import Guest | ||
|
||
|
||
class OracleLinuxGuest(Guest): | ||
""" This guest can provision Oracle Linux containers. """ | ||
|
||
name = 'ol' | ||
barebones_packages = [ | ||
'openssh-server', | ||
'python', | ||
] | ||
|
||
def install_barebones_packages(self): | ||
""" Installs packages when the guest is first provisionned. """ | ||
self.run(['yum', '-y', 'install'] + self.barebones_packages) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import unittest.mock | ||
|
||
from lxdock.guests import AlpineGuest | ||
|
||
|
||
class TestAlpineGuest: | ||
def test_can_install_barebones_packages(self): | ||
lxd_container = unittest.mock.Mock() | ||
lxd_container.execute.return_value = ('ok', 'ok', '') | ||
guest = AlpineGuest(lxd_container) | ||
guest.install_barebones_packages() | ||
assert lxd_container.execute.call_count == 4 | ||
assert lxd_container.execute.call_args_list[0][0] == (['apk', 'update'], ) | ||
assert lxd_container.execute.call_args_list[1][0] == \ | ||
(['apk', 'add'] + AlpineGuest.barebones_packages, ) | ||
assert lxd_container.execute.call_args_list[2][0] == \ | ||
(['rc-update', 'add', 'sshd'], ) | ||
assert lxd_container.execute.call_args_list[3][0] == \ | ||
(['/etc/init.d/sshd', 'start'], ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import unittest.mock | ||
|
||
from lxdock.guests import CentosGuest | ||
|
||
|
||
class TestCentosGuest: | ||
def test_can_install_barebones_packages(self): | ||
lxd_container = unittest.mock.Mock() | ||
lxd_container.execute.return_value = ('ok', 'ok', '') | ||
guest = CentosGuest(lxd_container) | ||
guest.install_barebones_packages() | ||
assert lxd_container.execute.call_count == 1 | ||
assert lxd_container.execute.call_args[0] == \ | ||
(['yum', '-y', 'install'] + CentosGuest.barebones_packages, ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import unittest.mock | ||
|
||
from lxdock.guests import FedoraGuest | ||
|
||
|
||
class TestFedoraGuest: | ||
def test_can_install_barebones_packages(self): | ||
lxd_container = unittest.mock.Mock() | ||
lxd_container.execute.return_value = ('ok', 'ok', '') | ||
guest = FedoraGuest(lxd_container) | ||
guest.install_barebones_packages() | ||
assert lxd_container.execute.call_count == 1 | ||
assert lxd_container.execute.call_args[0] == \ | ||
(['dnf', '-y', 'install'] + FedoraGuest.barebones_packages, ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import unittest.mock | ||
|
||
from lxdock.guests import GentooGuest | ||
|
||
|
||
class TestGentooGuest: | ||
def test_should_install_barebones_packages_if_not_installed(self): | ||
lxd_container = unittest.mock.Mock() | ||
# Retcode 1: "No installed packages matching {keyword}" | ||
lxd_container.execute.return_value = (1, 'ok', '') | ||
guest = GentooGuest(lxd_container) | ||
guest.install_barebones_packages() | ||
assert lxd_container.execute.call_count == 1 + 2 * len(GentooGuest.barebones_packages) | ||
assert lxd_container.execute.call_args_list[0][0] == \ | ||
(['emerge', 'app-portage/gentoolkit'], ) | ||
for i, p in enumerate(GentooGuest.barebones_packages): | ||
assert lxd_container.execute.call_args_list[2 * i + 1][0] == (['equery', 'list', p], ) | ||
assert lxd_container.execute.call_args_list[2 * i + 2][0] == (['emerge', p], ) | ||
|
||
def test_should_not_reinstall_barebones_packages_if_already_installed(self): | ||
lxd_container = unittest.mock.Mock() | ||
# Retcode 0: the package has been found locally | ||
lxd_container.execute.return_value = (0, 'ok', '') | ||
guest = GentooGuest(lxd_container) | ||
guest.install_barebones_packages() | ||
assert lxd_container.execute.call_count == 1 + len(GentooGuest.barebones_packages) | ||
assert lxd_container.execute.call_args_list[0][0] == \ | ||
(['emerge', 'app-portage/gentoolkit'], ) | ||
for i, p in enumerate(GentooGuest.barebones_packages): | ||
assert lxd_container.execute.call_args_list[i + 1][0] == (['equery', 'list', p], ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import unittest.mock | ||
|
||
from lxdock.guests import OpenSUSEGuest | ||
|
||
|
||
class TestOpenSUSEGuest: | ||
def test_can_install_barebones_packages(self): | ||
lxd_container = unittest.mock.Mock() | ||
lxd_container.execute.return_value = ('ok', 'ok', '') | ||
guest = OpenSUSEGuest(lxd_container) | ||
guest.install_barebones_packages() | ||
assert lxd_container.execute.call_count == 1 | ||
assert lxd_container.execute.call_args[0] == \ | ||
(['zypper', '--non-interactive', 'install'] + | ||
OpenSUSEGuest.barebones_packages, ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import unittest.mock | ||
|
||
from lxdock.guests import OracleLinuxGuest | ||
|
||
|
||
class TestOracleLinuxGuest: | ||
def test_can_install_barebones_packages(self): | ||
lxd_container = unittest.mock.Mock() | ||
lxd_container.execute.return_value = ('ok', 'ok', '') | ||
guest = OracleLinuxGuest(lxd_container) | ||
guest.install_barebones_packages() | ||
assert lxd_container.execute.call_count == 1 | ||
assert lxd_container.execute.call_args[0] == \ | ||
(['yum', '-y', 'install'] + OracleLinuxGuest.barebones_packages, ) |