Douglas Schilling Landgraf has uploaded a new change for review.

Change subject: engine_page: remove dep. from ovirt_config_setup.engine
......................................................................

engine_page: remove dep. from ovirt_config_setup.engine

ovirt_config_setup.engine is not available anymore.
This patch removes dependency.

Change-Id: Ia04f6fb1d3822828f543cfa4472d9e224162b5ff
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1102995
Signed-off-by: Douglas Schilling Landgraf <[email protected]>
---
M src/config.py.in
M src/engine_page.py
2 files changed, 88 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node-plugin-vdsm 
refs/changes/23/28423/1

diff --git a/src/config.py.in b/src/config.py.in
index 958666a..5a91d8b 100644
--- a/src/config.py.in
+++ b/src/config.py.in
@@ -15,6 +15,11 @@
 # MA  02110-1301, USA.  A copy of the GNU General Public License is
 # also available at http://www.gnu.org/copyleft/gpl.html.
 
+# Main plugin data
 PACKAGE_NAME = '@PACKAGE_NAME@'
 PACKAGE_VERSION = '@PACKAGE_VERSION@'
 engine_name = '@ENGINENAME@'
+
+# Configuration Files
+VDSM_CONFIG = '/etc/vdsm/vdsm.conf'
+VDSM_REG_CONFIG = '/etc/vdsm-reg/vdsm-reg.conf'
diff --git a/src/engine_page.py b/src/engine_page.py
index 66df4e2..bceda00 100644
--- a/src/engine_page.py
+++ b/src/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 ConfigParser
 import errno
 import httplib
 import os
@@ -30,6 +31,7 @@
 from ovirt.node import plugins, valid, ui, utils, log
 from ovirt.node.config.defaults import NodeConfigFileSection, SSH, Management
 from ovirt.node.plugins import Changeset
+from ovirt.node.utils.fs import Config
 
 from vdsm import vdscli
 
@@ -38,6 +40,36 @@
 """
 
 LOGGER = log.getLogger(__name__)
+
+
+def update_conf(conf_file, session, option, value):
+    """
+    Update configuration file
+
+    Args:
+    conf_file -- Configuration file
+    session -- Session in the configuration file
+    option -- option to be updated
+    value -- value to be updated in the option value
+
+    Returns: True or False
+    """
+
+    if not os.path.exists(conf_file):
+        raise IOError('Cannot find file to be updated.')
+
+    try:
+        cfg = ConfigParser.RawConfigParser()
+        cfg.read(conf_file)
+        cfg.set(session, option, value)
+
+        with open(conf_file, 'w+') as configfile:
+            cfg.write(configfile)
+    except ConfigParser.Error:
+        LOGGER.debug("Cannot write into file!", exc_info=True)
+        raise
+
+    return True
 
 
 def sync_mgmt():
@@ -292,12 +324,11 @@
 def findPort(engineServer, enginePort):
     """Function to find the correct port for a given server
     """
+    _TIMEOUT_FIND_HOST_SEC = 5
+
     # pylint: disable-msg=E0611,F0401
     sys.path.append('/usr/share/vdsm-reg')
     import deployUtil  # @UnresolvedImport
-
-    from ovirt_config_setup.engine import \
-        TIMEOUT_FIND_HOST_SEC  # @UnresolvedImport
 
     compatPort, sslPort = compatiblePort(enginePort)
 
@@ -324,7 +355,7 @@
         try:
             is_reachable = isHostReachable(host=engineServer,
                                            port=try_port, ssl=use_ssl,
-                                           timeout=TIMEOUT_FIND_HOST_SEC)
+                                           timeout=_TIMEOUT_FIND_HOST_SEC)
         except Exception:
             LOGGER.debug("Failed to reach engine: %s" % traceback.format_exc())
 
@@ -451,6 +482,11 @@
 
     def __init__(self, server, port):
         super(ActivateVDSM, self).__init__()
+
+        if not os.path.exists(config.VDSM_CONFIG):
+            self.create_vdsm_conf()
+            self.logger.info("Agent configuration files created.")
+
         self.server = server
         self.port = port
 
@@ -459,6 +495,21 @@
         cert_exists = cert_path and os.path.exists(cert_path)
 
         return cert_exists
+
+    def create_vdsm_conf(self):
+        cfg = ConfigParser.RawConfigParser()
+
+        cfg.add_section('addresses')
+        cfg.set('addresses', 'management_port', '54321')
+
+        cfg.add_section('vars')
+        cfg.set('vars', 'trust_store_path', '/etc/pki/vdsm/')
+        cfg.set('vars', 'ssl', 'true')
+
+        with open(config.VDSM_CONFIG, 'w') as configfile:
+            cfg.write(configfile)
+
+        Config().persist(config.VDSM_CONFIG)
 
     def commit(self):
         self.logger.info("Connecting to VDSM server")
@@ -471,11 +522,7 @@
         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
+        from vdsm import constants
 
         cfg = VDSM().retrieve()
 
@@ -483,19 +530,36 @@
         # menus are run after installation
         self.logger.info("Stopping vdsm-reg service")
         deployUtil._logExec([constants.EXT_SERVICE, 'vdsm-reg', 'stop'])
-        if write_vdsm_config(cfg["server"], cfg["port"]):
-            self.logger.info("Starting vdsm-reg service")
-            deployUtil._logExec([constants.EXT_SERVICE, 'vdsm-reg', 'start'])
-            sync_mgmt()
 
-            msgConf = "{engine_name} Configuration Successfully " \
-                " Updated".format(
-                    engine_name=config.engine_name)
-            self.logger.debug(msgConf)
-        else:
+        try:
+            update_conf(
+                config.VDSM_REG_CONFIG,
+                "vars",
+                "vdc_host_name",
+                cfg["server"]
+            )
+
+            update_conf(
+                config.VDSM_REG_CONFIG,
+                "vars",
+                "vdc_host_port",
+                cfg["port"]
+            )
+        except (ConfigParser.Error, IOError):
             mgmt = Management()
             mgmt.clear()
 
             msgConf = "{engine_name} Configuration Failed".format(
-                engine_name=config.engine_name)
+                engine_name=config.engine_name
+            )
+            self.logger.info(msgConf, exc_info=True)
             raise RuntimeError(msgConf)
+
+        self.logger.info("Starting vdsm-reg service")
+        deployUtil._logExec([constants.EXT_SERVICE, 'vdsm-reg', 'start'])
+        sync_mgmt()
+
+        msgConf = "{engine_name} Configuration Successfully Updated".format(
+            engine_name=config.engine_name
+        )
+        self.logger.debug(msgConf)


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia04f6fb1d3822828f543cfa4472d9e224162b5ff
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node-plugin-vdsm
Gerrit-Branch: node-3.0
Gerrit-Owner: Douglas Schilling Landgraf <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to