From a025e5357f52b8be0cb5bf30ea88722005ca1099 Mon Sep 17 00:00:00 2001
From: Vitaly Kuznetsov <vitty@altlinux.ru>
Date: Wed, 8 Sep 2010 16:57:45 +0000
Subject: [PATCH] Fix OS_VARIANT variable setting

This was introduced in efaa9b06d1e1e6d1678d0edd75b1ba37cf0de3d9.

 in OSCoreEnv:
  inst_os.name is pure operating system name (without variant) as variant is stripped
   in OSFromDisk(). So we always get variant = inst_os.supported_variants[0] (first
   variant in variants list).
  Adding argument os_name with full name (including variant) solves this problem.

Signed-off-by: Vitaly Kuznetsov <vitty@altlinux.ru>
Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
[modified by iustin to handle the call to OSCoreEnv from ValidateOS too]
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 lib/backend.py | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/lib/backend.py b/lib/backend.py
index 5b2bebde8..501696994 100644
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -1,7 +1,7 @@
 #
 #
 
-# Copyright (C) 2006, 2007 Google Inc.
+# Copyright (C) 2006, 2007, 2008, 2009, 2010 Google Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -1952,9 +1952,11 @@ def OSFromDisk(name, base_dir=None):
   return payload
 
 
-def OSCoreEnv(inst_os, os_params, debug=0):
+def OSCoreEnv(os_name, inst_os, os_params, debug=0):
   """Calculate the basic environment for an os script.
 
+  @type os_name: str
+  @param os_name: full operating system name (including variant)
   @type inst_os: L{objects.OS}
   @param inst_os: operating system for which the environment is being built
   @type os_params: dict
@@ -1977,7 +1979,7 @@ def OSCoreEnv(inst_os, os_params, debug=0):
   # OS variants
   if api_version >= constants.OS_API_V15:
     try:
-      variant = inst_os.name.split('+', 1)[1]
+      variant = os_name.split('+', 1)[1]
     except IndexError:
       variant = inst_os.supported_variants[0]
     result['OS_VARIANT'] = variant
@@ -2004,7 +2006,7 @@ def OSEnvironment(instance, inst_os, debug=0):
       cannot be found
 
   """
-  result = OSCoreEnv(inst_os, instance.osparams, debug=debug)
+  result = OSCoreEnv(instance.os, inst_os, instance.osparams, debug=debug)
 
   result['INSTANCE_NAME'] = instance.name
   result['INSTANCE_OS'] = instance.os
@@ -2541,7 +2543,7 @@ def ValidateOS(required, osname, checks, osparams):
   if constants.OS_VALIDATE_PARAMETERS in checks:
     _CheckOSPList(tbv, osparams.keys())
 
-  validate_env = OSCoreEnv(tbv, osparams)
+  validate_env = OSCoreEnv(osname, tbv, osparams)
   result = utils.RunCmd([tbv.verify_script] + checks, env=validate_env,
                         cwd=tbv.path)
   if result.failed:
-- 
GitLab