Blob Blame History Raw
From 94d411afc37de231c8a3101c30e1e6ba66ecd223 Mon Sep 17 00:00:00 2001
From: Tomas Jelinek <tojeline@redhat.com>
Date: Thu, 13 Jan 2022 17:32:38 +0100
Subject: [PATCH 4/4] fix creating empty cib

---
 pcs/utils.py                | 21 +++++++++++----------
 pcs_test/tier1/test_misc.py | 25 ++++++++++++++++++++++++-
 2 files changed, 35 insertions(+), 11 deletions(-)

diff --git a/pcs/utils.py b/pcs/utils.py
index 2f5949a7..b5b8af05 100644
--- a/pcs/utils.py
+++ b/pcs/utils.py
@@ -2135,16 +2135,17 @@ def write_empty_cib(cibfile):
     """
     Commandline options: no options
     """
-    empty_xml = """<?xml version="1.0" encoding="UTF-8"?>
-<cib admin_epoch="0" epoch="1" num_updates="1" validate-with="pacemaker-1.2">
-  <configuration>
-    <crm_config/>
-    <nodes/>
-    <resources/>
-    <constraints/>
-  </configuration>
-  <status/>
-</cib>"""
+    empty_xml = """
+        <cib admin_epoch="0" epoch="1" num_updates="1" validate-with="pacemaker-3.1">
+          <configuration>
+            <crm_config/>
+            <nodes/>
+            <resources/>
+            <constraints/>
+          </configuration>
+          <status/>
+        </cib>
+    """
     with open(cibfile, "w") as f:
         f.write(empty_xml)
 
diff --git a/pcs_test/tier1/test_misc.py b/pcs_test/tier1/test_misc.py
index 13312a69..abd02c61 100644
--- a/pcs_test/tier1/test_misc.py
+++ b/pcs_test/tier1/test_misc.py
@@ -1,8 +1,10 @@
+import os
 from unittest import TestCase
 
 from pcs_test.tools.assertions import AssertPcsMixin
 from pcs_test.tools.misc import (
     get_test_resource as rc,
+    get_tmp_dir,
     get_tmp_file,
     outdent,
     write_file_to_tmpfile,
@@ -19,7 +21,7 @@ class ParseArgvDashDash(TestCase, AssertPcsMixin):
     cmd = "constraint colocation add R1 with R2".split()
 
     def setUp(self):
-        self.temp_cib = get_tmp_file("tier1_misc")
+        self.temp_cib = get_tmp_file("tier1_misc_dashdash")
         write_file_to_tmpfile(rc("cib-empty.xml"), self.temp_cib)
         self.pcs_runner = PcsRunner(self.temp_cib.name)
         self.allowed_roles = format_list(const.PCMK_ROLES)
@@ -89,3 +91,24 @@ class ParseArgvDashDash(TestCase, AssertPcsMixin):
                 """
             ),
         )
+
+
+class EmptyCibIsPcmk2Compatible(TestCase, AssertPcsMixin):
+    # This test verifies that a default empty CIB created by pcs when -f points
+    # to an empty file conforms to minimal schema version supported by
+    # pacemaker 2.0. If pcs prints a message that CIB schema has been upgraded,
+    # then the test fails and shows there is a bug. Bundle with promoted-max
+    # requires CIB compliant with schema 3.1, which was introduced in pacemaker
+    # 2.0.0.
+    def setUp(self):
+        self.cib_dir = get_tmp_dir("tier1_misc_empty_cib")
+        self.pcs_runner = PcsRunner(os.path.join(self.cib_dir.name, "cib.xml"))
+
+    def tearDown(self):
+        self.cib_dir.cleanup()
+
+    def test_success(self):
+        self.assert_pcs_success(
+            "resource bundle create b container docker image=my.img promoted-max=1".split(),
+            "",
+        )
-- 
2.31.1