diff --git a/os_xenapi/cmd/bootstrap.py b/os_xenapi/cmd/bootstrap.py index 04540d6..4534251 100644 --- a/os_xenapi/cmd/bootstrap.py +++ b/os_xenapi/cmd/bootstrap.py @@ -21,6 +21,7 @@ import getopt import json import sys +from os_xenapi.utils.common_conf import enable_linux_bridge from os_xenapi.utils.himn import config_himn from os_xenapi.utils.iptables import config_iptables from os_xenapi.utils.sshclient import SSHClient @@ -98,6 +99,7 @@ def main(): config_himn(himn_ip) config_iptables(dom0_client) install_plugins_to_dom0(dom0_client) + enable_linux_bridge(dom0_client) # Gather XenAPI relative facts and save them into file. get_and_store_facts(dom0_client, facts_file) diff --git a/os_xenapi/tests/cmd/test_bootstrap.py b/os_xenapi/tests/cmd/test_bootstrap.py index 596b3e5..b4ba2e0 100644 --- a/os_xenapi/tests/cmd/test_bootstrap.py +++ b/os_xenapi/tests/cmd/test_bootstrap.py @@ -75,8 +75,9 @@ class GetXenapiFactsTestCase(base.TestCase): @mock.patch.object(bootstrap, 'config_iptables') @mock.patch.object(bootstrap, 'install_plugins_to_dom0') @mock.patch.object(bootstrap, 'get_and_store_facts') - def test_bootstrap(self, mock_facts, mock_plugin, mock_iptables, - mock_himn, mock_client, mock_parse): + @mock.patch.object(bootstrap, 'enable_linux_bridge') + def test_bootstrap(self, mock_enable_lbr, mock_facts, mock_plugin, + mock_iptables, mock_himn, mock_client, mock_parse): fake_opts = {'himn-ip': '169.254.0.1', 'passwd': 'passwd', 'user-name': 'root'} @@ -91,3 +92,4 @@ class GetXenapiFactsTestCase(base.TestCase): mock_plugin.assert_called_with(mock.sentinel.sshclient) mock_facts.assert_called_with(mock.sentinel.sshclient, bootstrap.DEF_XENAPI_FACTS_FILE) + mock_enable_lbr.assert_called_with(mock.sentinel.sshclient) diff --git a/os_xenapi/tests/utils/test_common_conf.py b/os_xenapi/tests/utils/test_common_conf.py new file mode 100644 index 0000000..0f5788c --- /dev/null +++ b/os_xenapi/tests/utils/test_common_conf.py @@ -0,0 +1,26 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +import mock +from os_xenapi.tests import base +from os_xenapi.utils import common_conf + + +class XenapiConfOptTestCase(base.TestCase): + def test_enable_linux_bridge(self): + client = mock.Mock() + expect_cmd = "if [ -f /etc/modprobe.d/blacklist-bridge.conf ]; then\n"\ + " mv -f /etc/modprobe.d/blacklist-bridge.conf" \ + " /etc/modprobe.d/blacklist-bridge.conf_bak\n" \ + "fi" + + common_conf.enable_linux_bridge(client) + client.ssh.assert_called_once_with(expect_cmd) diff --git a/os_xenapi/utils/common_conf.py b/os_xenapi/utils/common_conf.py new file mode 100644 index 0000000..2e5c97a --- /dev/null +++ b/os_xenapi/utils/common_conf.py @@ -0,0 +1,38 @@ +# Copyright 2018 Citrix Systems +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +"""The configure utils + +It contains the configure operations.""" +import sys + +from os_xenapi.utils import common_function +from os_xenapi.utils import sshclient + + +def enable_linux_bridge(dom0_client): + # disable to bridge blacklist to allow linux bridge create on Dom0 + + dom0_client.ssh("if [ -f /etc/modprobe.d/blacklist-bridge.conf ]; then\n" + " mv -f /etc/modprobe.d/blacklist-bridge.conf" + " /etc/modprobe.d/blacklist-bridge.conf_bak\n" + "fi") + + +if __name__ == '__main__': + if len(sys.argv) != 4: + common_function.exit_with_error("Wrong parameters input.") + dom0_himn_ip, user_name, password = sys.argv[1:] + dom0_client = sshclient.SSHClient(dom0_himn_ip, user_name, password) + enable_linux_bridge(dom0_client)