[node-patches] Change in ovirt-node[master]: tui: Add engine page logic

fabiand at fedoraproject.org fabiand at fedoraproject.org
Tue Jan 29 19:17:56 UTC 2013


Fabian Deutsch has uploaded a new change for review.

Change subject: tui: Add engine page logic
......................................................................

tui: Add engine page logic

Previously the engine page used a stub. Thispatch adds the required
logic so an engine registration happens.

Change-Id: I62f4b5f398a11137676af3b4a729ca2728224bb9
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/tui/src/ovirt/node/base.py
M scripts/tui/src/ovirt/node/setup/engine_page.py
M scripts/tui/src/ovirt/node/utils/security.py
3 files changed, 149 insertions(+), 31 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/25/11525/1

diff --git a/scripts/tui/src/ovirt/node/base.py b/scripts/tui/src/ovirt/node/base.py
index c929696..74e6237 100644
--- a/scripts/tui/src/ovirt/node/base.py
+++ b/scripts/tui/src/ovirt/node/base.py
@@ -40,6 +40,11 @@
         """Contructor."""
         self._logger = logging.getLogger(self.__module__)
 
+    def _super(self):
+        """Return the parent class of this obj
+        """
+        return super(self.__class__, self)
+
     def new_signal(self):
         return Base.Signal(self)
 
diff --git a/scripts/tui/src/ovirt/node/setup/engine_page.py b/scripts/tui/src/ovirt/node/setup/engine_page.py
index 9f03c7e..a3a9a62 100644
--- a/scripts/tui/src/ovirt/node/setup/engine_page.py
+++ b/scripts/tui/src/ovirt/node/setup/engine_page.py
@@ -18,6 +18,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA  02110-1301, USA.  A copy of the GNU General Public License is
 # also available at http://www.gnu.org/copyleft/gpl.html.
+import sys
 from ovirt.node import plugins, valid, ui, utils
 from ovirt.node.config.defaults import NodeConfigFileSection
 from ovirt.node.plugins import Changeset
@@ -36,36 +37,36 @@
 
     def model(self):
         model = {
-            "vdsm.address": "",
-            "vdsm.port": "7634",
-            "vdsm.connect_and_validate": False,
-            "vdsm.password": "",
-            "vdsm.password_confirmation": "",
+            "vdsm_cfg.address": "",
+            "vdsm_cfg.port": "7634",
+            "vdsm_cfg.connect_and_validate": False,
+            "vdsm_cfg.password": "",
+            "vdsm_cfg.password_confirmation": "",
         }
         return model
 
     def validators(self):
-        same_as_password = plugins.Validator.SameAsIn(self, "vdsm.password",
+        same_as_password = plugins.Validator.SameAsIn(self, "vdsm_cfg.password",
                                                       "Password")
-        return {"vdsm.address": valid.FQDNOrIPAddress() | valid.Empty(),
-                "vdsm.port": valid.Port(),
-                "vdsm.password": valid.Text(),
-                "vdsm.password_confirmation": same_as_password,
+        return {"vdsm_cfg.address": valid.FQDNOrIPAddress() | valid.Empty(),
+                "vdsm_cfg.port": valid.Port(),
+                "vdsm_cfg.password": valid.Text(),
+                "vdsm_cfg.password_confirmation": same_as_password,
                 }
 
     def ui_content(self):
         ws = [ui.Header("header[0]", "oVirt Engine Configuration"),
-              ui.Entry("vdsm.address", "Management Server:"),
-              ui.Entry("vdsm.port", "Management Server Port:"),
+              ui.Entry("vdsm_cfg.address", "Management Server:"),
+              ui.Entry("vdsm_cfg.port", "Management Server Port:"),
               ui.Divider("divider[0]"),
-              ui.Checkbox("vdsm.connect_and_validate",
+              ui.Checkbox("vdsm_cfg.connect_and_validate",
                           "Connect to oVirt Engine and Validate Certificate"),
               ui.Divider("divider[1]"),
-              ui.Label("vdsm.password._label",
+              ui.Label("vdsm_cfg.password._label",
                        "Optional password for adding Node through oVirt " +
                        "Engine UI"),
-              ui.PasswordEntry("vdsm.password", "Password:"),
-              ui.PasswordEntry("vdsm.password_confirmation",
+              ui.PasswordEntry("vdsm_cfg.password", "Password:"),
+              ui.PasswordEntry("vdsm_cfg.password_confirmation",
                                "Confirm Password:"),
               ]
         # Save it "locally" as a dict, for better accessability
@@ -88,7 +89,7 @@
 
         txs = utils.Transaction("Configuring oVirt Engine")
 
-        vdsm_keys = ["vdsm.address", "vdsm.port"]
+        vdsm_keys = ["vdsm_cfg.address", "vdsm_cfg.port"]
         if changes.contains_any(vdsm_keys):
             values = effective_model.values_for(vdsm_keys)
             self.logger.debug("Setting VDSM server and port (%s)" % values)
@@ -98,13 +99,13 @@
             model.update(*values)
             txs += model.transaction()
 
-        if changes.contains_any(["vdsm.password_confirmation"]):
+        if changes.contains_any(["vdsm_cfg.password_confirmation"]):
             self.logger.debug("Setting engine password")
             txs += [SetEnginePassword()]
 
-        if changes.contains_any(["vdsm.connect_and_validate"]):
+        if changes.contains_any(["vdsm_cfg.connect_and_validate"]):
             self.logger.debug("Connecting to engine")
-            txs += [ActivateVDSM()]
+            txs += [ActivateVDSM(changes["vdsm_cfg.connect_and_validate"])]
 
         progress_dialog = ui.TransactionProgressDialog("dialog.txs", txs, self)
         progress_dialog.run()
@@ -113,8 +114,14 @@
         return self.ui_content()
 
 
+#
+#
+# Functions and classes to support the UI
+#
+#
+
 class VDSM(NodeConfigFileSection):
-    """Class to handle VDSM configuration
+    """Class to handle VDSM configuration in /etc/default/ovirt file
 
     >>> from ovirt.node.config.defaults import ConfigFile, SimpleProvider
     >>> fn = "/tmp/cfg_dummy"
@@ -148,28 +155,134 @@
         return tx
 
 
+class SetRootPassword(utils.Transaction.Element):
+    title = "Setting root password and starting sshd"
+
+    def __init__(self, password):
+        super(SetRootPassword, self).__init__()
+        self.password = password
+
+    def commit(self):
+        passwd = utils.security.Passwd()
+        passwd.set_password("root", self.password)
+
+        sshd = utils.security.Ssh()
+        sshd.password_authentication(True)
+        sshd.restart()
+
+
 class ActivateVDSM(utils.Transaction.Element):
     title = "Activating VDSM"
 
-    def __init__(self):
+    def __init__(self, verify_engine_cert):
         super(ActivateVDSM, self).__init__()
-        self.vdsm = VDSM()
+        self.vdsm_cfg = VDSM()
+        self.verify_engine_cert = verify_engine_cert
 
     def prepare(self):
         """Ping the management server before we try to activate
         the connection to it
         """
-        cfg = dict(self.vdsm.retrieve())
-        server = cfg["server"]
-        retval = utils.process.system("ping -c 1 '%s'" % server)
-        self.logger.debug("Pinged server with %s" % retval)
-        if retval != 0:
-            raise RuntimeError("Unable to reach given server: %s" %
-                               server)
+        cfg = dict(self.vdsm_cfg.retrieve())
+        self.engineServer = cfg["server"]
+        self.enginePort = cfg["port"]
+        if self.engineServer:
+            newPort = self.__prepare_server(self.engineServer, self.enginePort)
+            self.enginePort = newPort
+
+    def __prepare_server(self, engineServer, enginePort):
+        # pylint: disable-msg=E0611,F0401
+        sys.path.append('/usr/share/vdsm-reg')
+        import deployUtil  # @UnresolvedImport
+
+        sys.path.append('/usr/share/vdsm')
+        from vdsm import constants  # @UnresolvedImport
+
+        from ovirt_config_setup.engine import \
+            isHostReachable  # @UnresolvedImport
+        from ovirt_config_setup.engine import \
+            TIMEOUT_FIND_HOST_SEC  # @UnresolvedImport
+        from ovirt_config_setup.engine import \
+            compatiblePort  # @UnresolvedImport
+        # pylint: enable-msg=E0611,F0401
+
+        compatPort, sslPort = compatiblePort(self.enginePort)
+
+        deployUtil.nodeCleanup()
+        if not isHostReachable(host=engineServer,
+                               port=enginePort, ssl=sslPort,
+                               timeout=TIMEOUT_FIND_HOST_SEC):
+            if compatPort is None:
+                # Try one more time with SSL=False
+                if not isHostReachable(host=engineServer,
+                                       port=enginePort, ssl=False,
+                                       timeout=TIMEOUT_FIND_HOST_SEC):
+                    msgConn = "Can't connect to @ENGINENAME@ in the " + \
+                              "specific port %s" % enginePort
+                    raise RuntimeError(msgConn)
+            else:
+                msgConn = "Can't connect to @ENGINENAME@ port %s," \
+                    " trying compatible port %s" % \
+                    (enginePort, compatPort)
+
+                #  FIXME self.notice(msgConn)
+
+                if not isHostReachable(host=self.engineServer,
+                                       port=compatPort, ssl=sslPort,
+                                       timeout=TIMEOUT_FIND_HOST_SEC):
+                    msgConn = "Can't connect to @ENGINENAME@ using" \
+                        " compatible port %s" % compatPort
+                    raise RuntimeError(msgConn)
+                else:
+                    # compatible port found
+                    enginePort = compatPort
+
+        return enginePort
 
     def commit(self):
         self.logger.info("Connecting to VDSM server")
 
+        from ovirtnode.ovirtfunctions import ovirt_store_config
+
+        # pylint: disable-msg=E0611,F0401
+        sys.path.append('/usr/share/vdsm-reg')
+        import deployUtil  # @UnresolvedImport
+
+        sys.path.append('/usr/share/vdsm')
+        from vdsm import constants  # @UnresolvedImport
+
+        from ovirt_config_setup.engine import \
+            write_vdsm_config  # @UnresolvedImport
+        # pylint: enable-msg=E0611,F0401
+
+        if self.verify_engine_cert:
+            if deployUtil.getRhevmCert(self.engineServer,
+                                       self.enginePort):
+                _, _, path = deployUtil.certPaths('')
+                fp = deployUtil.generateFingerPrint(path)
+                #
+                # FIXME
+                #
+                # a) Allow interactive confirmation of key
+                # b) Remind to verify key (with dialog on ui.Page)
+                #
+                ovirt_store_config(path)
+            else:
+                msgCert = "Failed downloading @ENGINENAME@ certificate"
+                raise RuntimeError(msgCert)
+        # Stopping vdsm-reg may fail but its ok - its in the case when the
+        # menus are run after installation
+        deployUtil._logExec([constants.EXT_SERVICE, 'vdsm-reg', 'stop'])
+        if write_vdsm_config(self.engineServer, self.enginePort):
+            deployUtil._logExec([constants.EXT_SERVICE, 'vdsm-reg',
+                                 'start'])
+
+            msgConf = "@ENGINENAME@ Configuration Successfully Updated"
+            self.logger.debug(msgConf)
+        else:
+            msgConf = "@ENGINENAME@ Configuration Failed"
+            raise RuntimeError(msgConf)
+
 
 class SetEnginePassword(utils.Transaction.Element):
     title = "Setting Engine password"
diff --git a/scripts/tui/src/ovirt/node/utils/security.py b/scripts/tui/src/ovirt/node/utils/security.py
index 9563422..01ecb2c 100644
--- a/scripts/tui/src/ovirt/node/utils/security.py
+++ b/scripts/tui/src/ovirt/node/utils/security.py
@@ -21,7 +21,7 @@
 from ovirt.node import base, valid, utils
 import process
 import os.path
-import PAM as _PAM
+import PAM as _PAM  # @UnresolvedImport
 
 """
 Some convenience functions related to security


--
To view, visit http://gerrit.ovirt.org/11525
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I62f4b5f398a11137676af3b4a729ca2728224bb9
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Fabian Deutsch <fabiand at fedoraproject.org>



More information about the node-patches mailing list