Exemplo n.º 1
0
    def bundle_create(self, bundle_id=None, container_type=None, **params):
        if "container_options" not in params:
            params["container_options"] = {"image": self.image}

        resource.bundle_create(self.env_assist.get_env(),
                               bundle_id=bundle_id or self.bundle_id,
                               container_type=container_type
                               or self.container_type,
                               **params)
Exemplo n.º 2
0
    def bundle_create(self, bundle_id=None, container_type=None, **params):
        if "container_options" not in params:
            params["container_options"] = {"image": self.image}

        resource.bundle_create(
            self.env_assist.get_env(),
            bundle_id=bundle_id or self.bundle_id,
            container_type=container_type or self.container_type,
            **params
        )
Exemplo n.º 3
0
    def test_cib_upgrade(self):
        self.runner.set_runs(
            fixture.calls_cib_load_and_upgrade(self.fixture_cib_pre) +
            fixture.calls_cib(self.fixture_cib_pre,
                              self.fixture_resources_bundle_simple,
                              cib_base_file=self.cib_base_file))

        resource.bundle_create(self.env, "B1", "docker", {
            "image": "pcs:test",
        })

        self.env.report_processor.assert_reports([
            (severities.INFO, report_codes.CIB_UPGRADE_SUCCESSFUL, {}, None),
        ])
        self.runner.assert_everything_launched()
Exemplo n.º 4
0
 def test_forceable_options_errors(self):
     self.runner.set_runs(
         fixture.call_cib_load(
             self.fixture_cib_resources(self.fixture_cib_pre)))
     assert_raise_library_error(
         lambda: resource.bundle_create(
             self.env,
             "B1",
             "docker", {
                 "image": "pcs:test",
             },
             storage_map=[
                 {
                     "source-dir": "/tmp/docker1a",
                     "target-dir": "/tmp/docker1b",
                     "extra": "option",
                 },
             ]),
         (severities.ERROR, report_codes.INVALID_OPTION, {
             "option_names": [
                 "extra",
             ],
             "option_type": "storage-map",
             "allowed": self.allowed_options,
         }, report_codes.FORCE_OPTIONS),
     )
Exemplo n.º 5
0
 def test_options_errors(self):
     self.runner.set_runs(
         fixture.call_cib_load(
             self.fixture_cib_resources(self.fixture_cib_pre)))
     assert_raise_library_error(
         lambda: resource.bundle_create(self.env,
                                        "B1",
                                        "docker", {
                                            "image": "pcs:test",
                                        },
                                        network_options={
                                            "control-port": "0",
                                            "host-netmask": "abc",
                                            "extra": "option",
                                        }),
         (severities.ERROR, report_codes.INVALID_OPTION_VALUE, {
             "option_name": "control-port",
             "option_value": "0",
             "allowed_values": "a port number (1-65535)",
         }, None),
         (severities.ERROR, report_codes.INVALID_OPTION_VALUE, {
             "option_name": "host-netmask",
             "option_value": "abc",
             "allowed_values": "a number of bits of the mask (1-32)",
         }, report_codes.FORCE_OPTIONS),
         (severities.ERROR, report_codes.INVALID_OPTION, {
             "option_names": [
                 "extra",
             ],
             "option_type": "network",
             "allowed": self.allowed_options,
         }, report_codes.FORCE_OPTIONS),
     )
     self.runner.assert_everything_launched()
Exemplo n.º 6
0
 def test_options_errors(self):
     self.env_assist.assert_raise_library_error(
         lambda: resource.bundle_create(self.env_assist.get_env(),
                                        "B1",
                                        "docker",
                                        container_options={
                                            "replicas-per-host": "0",
                                            "replicas": "0",
                                            "masters": "-1",
                                        },
                                        force_options=True),
         [
             (severities.ERROR, report_codes.REQUIRED_OPTION_IS_MISSING, {
                 "option_type": "container",
                 "option_names": [
                     "image",
                 ],
             }, None),
             (severities.ERROR, report_codes.INVALID_OPTION_VALUE, {
                 "option_name": "masters",
                 "option_value": "-1",
                 "allowed_values": "a non-negative integer",
             }, None),
             (severities.ERROR, report_codes.INVALID_OPTION_VALUE, {
                 "option_name": "replicas",
                 "option_value": "0",
                 "allowed_values": "a positive integer",
             }, None),
             (severities.ERROR, report_codes.INVALID_OPTION_VALUE, {
                 "option_name": "replicas-per-host",
                 "option_value": "0",
                 "allowed_values": "a positive integer",
             }, None),
         ])
Exemplo n.º 7
0
 def test_forceable_options_errors(self):
     self.runner.set_runs(
         fixture.call_cib_load(
             self.fixture_cib_resources(self.fixture_cib_pre)))
     assert_raise_library_error(
         lambda: resource.bundle_create(self.env,
                                        "B1",
                                        "docker", {
                                            "image": "pcs:test",
                                        },
                                        port_map=[
                                            {
                                                "range": "3000",
                                                "extra": "option",
                                            },
                                        ]),
         (severities.ERROR, report_codes.INVALID_OPTION, {
             "option_names": [
                 "extra",
             ],
             "option_type": "port-map",
             "allowed": self.allowed_options,
         }, report_codes.FORCE_OPTIONS),
         (severities.ERROR, report_codes.INVALID_OPTION_VALUE, {
             "option_name": "range",
             "option_value": "3000",
             "allowed_values": "port-port",
         }, report_codes.FORCE_OPTIONS),
     )
Exemplo n.º 8
0
 def test_success(self):
     self.assert_command_effect(
         self.fixture_cib_pre,
         lambda: resource.bundle_create(self.env,
                                        "B1",
                                        "docker",
                                        container_options={
                                            "image": "pcs:test",
                                        },
                                        meta_attributes={
                                            "target-role": "Stopped",
                                            "is-managed": "false",
                                        }), """
             <resources>
                 <bundle id="B1">
                     <docker image="pcs:test" />
                     <meta_attributes id="B1-meta_attributes">
                         <nvpair id="B1-meta_attributes-is-managed"
                             name="is-managed" value="false" />
                         <nvpair id="B1-meta_attributes-target-role"
                             name="target-role" value="Stopped" />
                     </meta_attributes>
                 </bundle>
             </resources>
         """)
Exemplo n.º 9
0
 def test_options_forced(self):
     self.assert_command_effect(
         self.fixture_cib_pre,
         lambda: resource.bundle_create(self.env,
                                        "B1",
                                        "docker", {
                                            "image": "pcs:test",
                                        },
                                        network_options={
                                            "host-netmask": "abc",
                                            "extra": "option",
                                        },
                                        force_options=True), """
             <resources>
                 <bundle id="B1">
                     <docker image="pcs:test" />
                     <network host-netmask="abc" extra="option" />
                 </bundle>
             </resources>
         """,
         [
             (severities.WARNING, report_codes.INVALID_OPTION_VALUE, {
                 "option_name": "host-netmask",
                 "option_value": "abc",
                 "allowed_values": "a number of bits of the mask (1-32)",
             }, None),
             (severities.WARNING, report_codes.INVALID_OPTION, {
                 "option_names": [
                     "extra",
                 ],
                 "option_type": "network",
                 "allowed": self.allowed_options,
             }, None),
         ])
Exemplo n.º 10
0
 def test_all_options(self):
     self.assert_command_effect(
         self.fixture_cib_pre, lambda: resource.bundle_create(
             self.env,
             "B1",
             "docker", {
                 "image": "pcs:test",
             },
             network_options={
                 "control-port": "12345",
                 "host-interface": "eth0",
                 "host-netmask": "24",
                 "ip-range-start": "192.168.100.200",
             }), """
             <resources>
                 <bundle id="B1">
                     <docker image="pcs:test" />
                     <network
                         control-port="12345"
                         host-interface="eth0"
                         host-netmask="24"
                         ip-range-start="192.168.100.200"
                     />
                 </bundle>
             </resources>
         """)
Exemplo n.º 11
0
 def test_forceable_options_errors(self):
     self.env_assist.assert_raise_library_error(
         lambda: resource.bundle_create(self.env_assist.get_env(),
                                        "B1",
                                        "docker", {
                                            "image": "pcs:test",
                                        },
                                        port_map=[
                                            {
                                                "range": "3000",
                                                "extra": "option",
                                            },
                                        ]),
         [
             (severities.ERROR, report_codes.INVALID_OPTIONS, {
                 "option_names": [
                     "extra",
                 ],
                 "option_type": "port-map",
                 "allowed": self.allowed_options,
                 "allowed_patterns": [],
             }, report_codes.FORCE_OPTIONS),
             (severities.ERROR, report_codes.INVALID_OPTION_VALUE, {
                 "option_name": "range",
                 "option_value": "3000",
                 "allowed_values": "port-port",
             }, report_codes.FORCE_OPTIONS),
         ])
Exemplo n.º 12
0
 def test_options_errors(self):
     self.env_assist.assert_raise_library_error(
         lambda: resource.bundle_create(self.env_assist.get_env(),
                                        "B1",
                                        "docker", {
                                            "image": "pcs:test",
                                        },
                                        network_options={
                                            "control-port": "0",
                                            "host-netmask": "abc",
                                            "extra": "option",
                                        }),
         [
             (severities.ERROR, report_codes.INVALID_OPTION_VALUE, {
                 "option_name": "control-port",
                 "option_value": "0",
                 "allowed_values": "a port number (1-65535)",
             }, None),
             (severities.ERROR, report_codes.INVALID_OPTION_VALUE, {
                 "option_name": "host-netmask",
                 "option_value": "abc",
                 "allowed_values": "a number of bits of the mask (1-32)",
             }, report_codes.FORCE_OPTIONS),
             (severities.ERROR, report_codes.INVALID_OPTIONS, {
                 "option_names": [
                     "extra",
                 ],
                 "option_type": "network",
                 "allowed": self.allowed_options,
                 "allowed_patterns": [],
             }, report_codes.FORCE_OPTIONS),
         ])
Exemplo n.º 13
0
 def test_unknow_option_forced(self):
     self.assert_command_effect(
         self.fixture_cib_pre,
         lambda: resource.bundle_create(self.env,
                                        "B1",
                                        "docker", {
                                            "image": "pcs:test",
                                            "extra": "option",
                                        },
                                        force_options=True), """
             <resources>
                 <bundle id="B1">
                     <docker image="pcs:test" extra="option" />
                 </bundle>
             </resources>
         """,
         [
             (severities.WARNING, report_codes.INVALID_OPTION, {
                 "option_names": [
                     "extra",
                 ],
                 "option_type": "container",
                 "allowed": self.allowed_options,
             }, None),
         ])
Exemplo n.º 14
0
 def test_all_options(self):
     self.assert_command_effect(
         self.fixture_cib_pre, lambda: resource.bundle_create(
             self.env, "B1", "docker", {
                 "image": "pcs:test",
                 "masters": "0",
                 "network": "extra network settings",
                 "options": "extra options",
                 "run-command": "/bin/true",
                 "replicas": "4",
                 "replicas-per-host": "2",
             }), """
             <resources>
                 <bundle id="B1">
                     <docker
                         image="pcs:test"
                         masters="0"
                         network="extra network settings"
                         options="extra options"
                         replicas="4"
                         replicas-per-host="2"
                         run-command="/bin/true"
                     />
                 </bundle>
             </resources>
         """)
Exemplo n.º 15
0
 def simple_bundle_create(self, wait=False):
     return resource.bundle_create(
         self.env,
         "B1",
         "docker",
         {"image": "pcs:test"},
         wait=wait,
     )
Exemplo n.º 16
0
def simple_bundle_create(env, wait=TIMEOUT, disabled=False):
    return resource.bundle_create(
        env,
        "B1",
        "docker",
        container_options={"image": "pcs:test"},
        ensure_disabled=disabled,
        wait=wait,
    )
Exemplo n.º 17
0
    def test_forceable_options_errors_forced(self):
        self.config.env.push_cib(resources="""
                <resources>
                    <bundle id="B1">
                        <docker image="pcs:test" />
                        <network>
                            <port-mapping
                                id="B1-port-map-3000"
                                extra="option"
                                range="3000"
                            />
                        </network>
                    </bundle>
                </resources>
            """, )

        resource.bundle_create(self.env_assist.get_env(),
                               "B1",
                               "docker", {
                                   "image": "pcs:test",
                               },
                               port_map=[
                                   {
                                       "range": "3000",
                                       "extra": "option",
                                   },
                               ],
                               force_options=True)

        self.env_assist.assert_reports([
            (severities.WARNING, report_codes.INVALID_OPTIONS, {
                "option_names": [
                    "extra",
                ],
                "option_type": "port-map",
                "allowed": self.allowed_options,
                "allowed_patterns": [],
            }, None),
            (severities.WARNING, report_codes.INVALID_OPTION_VALUE, {
                "option_name": "range",
                "option_value": "3000",
                "allowed_values": "port-port",
            }, None),
        ])
Exemplo n.º 18
0
 def test_minimal(self):
     self.assert_command_effect(
         self.fixture_cib_pre,
         lambda: resource.bundle_create(self.env,
                                        "B1",
                                        "docker",
                                        container_options={
                                            "image": "pcs:test",
                                        }),
         self.fixture_resources_bundle_simple)
Exemplo n.º 19
0
 def test_no_options(self):
     self.assert_command_effect(
         self.fixture_cib_pre,
         lambda: resource.bundle_create(self.env,
                                        "B1",
                                        "docker", {
                                            "image": "pcs:test",
                                        },
                                        network_options={}),
         self.fixture_resources_bundle_simple)
Exemplo n.º 20
0
 def test_disabled(self):
     self.config.env.push_cib(resources="""
             <resources>
                 <bundle id="B1">
                     <meta_attributes id="B1-meta_attributes">
                         <nvpair id="B1-meta_attributes-target-role"
                             name="target-role" value="Stopped" />
                     </meta_attributes>
                     <docker image="pcs:test" />
                 </bundle>
             </resources>
         """)
     resource.bundle_create(self.env_assist.get_env(),
                            "B1",
                            "docker",
                            container_options={
                                "image": "pcs:test",
                            },
                            ensure_disabled=True)
Exemplo n.º 21
0
 def _test_options_errors(self):
     self.env_assist.assert_raise_library_error(
         lambda: resource.bundle_create(self.env_assist.get_env(),
                                        "B1",
                                        self.container_type,
                                        container_options={
                                            "replicas-per-host": "0",
                                            "replicas": "0",
                                            "masters": "-1",
                                            "promoted-max": "-2",
                                        },
                                        force_options=True),
         [
             (severities.ERROR, report_codes.REQUIRED_OPTION_IS_MISSING, {
                 "option_type": "container",
                 "option_names": [
                     "image",
                 ],
             }, None),
             (severities.ERROR, report_codes.INVALID_OPTION_VALUE, {
                 "option_name": "masters",
                 "option_value": "-1",
                 "allowed_values": "a non-negative integer",
             }, None),
             (severities.ERROR, report_codes.INVALID_OPTION_VALUE, {
                 "option_name": "promoted-max",
                 "option_value": "-2",
                 "allowed_values": "a non-negative integer",
             }, None),
             (severities.ERROR, report_codes.MUTUALLY_EXCLUSIVE_OPTIONS, {
                 "option_names": [
                     "masters",
                     "promoted-max",
                 ],
                 "option_type": "container",
             }, None),
             (severities.ERROR, report_codes.INVALID_OPTION_VALUE, {
                 "option_name": "replicas",
                 "option_value": "0",
                 "allowed_values": "a positive integer",
             }, None),
             (severities.ERROR, report_codes.INVALID_OPTION_VALUE, {
                 "option_name": "replicas-per-host",
                 "option_value": "0",
                 "allowed_values": "a positive integer",
             }, None),
         ])
     self.env_assist.assert_reports([
         (severities.WARNING, report_codes.DEPRECATED_OPTION, {
             "option_name": "masters",
             "option_type": "container",
             "replaced_by": ["promoted-max"],
         }, None),
     ])
Exemplo n.º 22
0
 def test_several_mappings_and_handle_their_ids(self):
     self.config.env.push_cib(resources="""
             <resources>
                 <bundle id="B1">
                     <docker image="pcs:test" />
                     <network>
                         <port-mapping id="B1-port-map-1001-1" port="1001" />
                         <port-mapping
                             id="B1-port-map-1001"
                             internal-port="2002"
                             port="2000"
                         />
                         <port-mapping
                             id="B1-port-map-3000-3300"
                             range="3000-3300"
                         />
                     </network>
                 </bundle>
             </resources>
         """)
     resource.bundle_create(
         self.env_assist.get_env(),
         "B1",
         "docker",
         {
             "image": "pcs:test",
         },
         port_map=[
             {
                 "port": "1001",
             },
             {
                 # use an autogenerated id of the previous item
                 "id": "B1-port-map-1001",
                 "port": "2000",
                 "internal-port": "2002",
             },
             {
                 "range": "3000-3300",
             },
         ])
Exemplo n.º 23
0
    def test_forceable_options_errors_forced(self):
        self.config.env.push_cib(resources="""
                <resources>
                    <bundle id="B1">
                        <docker image="pcs:test" />
                        <storage>
                            <storage-mapping
                                id="B1-storage-map"
                                source-dir="/tmp/docker1a"
                                target-dir="/tmp/docker1b"
                                extra="option"
                            />
                        </storage>
                    </bundle>
                </resources>
            """, )

        resource.bundle_create(self.env_assist.get_env(),
                               "B1",
                               "docker", {
                                   "image": "pcs:test",
                               },
                               storage_map=[
                                   {
                                       "source-dir": "/tmp/docker1a",
                                       "target-dir": "/tmp/docker1b",
                                       "extra": "option",
                                   },
                               ],
                               force_options=True)

        self.env_assist.assert_reports([
            (severities.WARNING, report_codes.INVALID_OPTIONS, {
                "option_names": [
                    "extra",
                ],
                "option_type": "storage-map",
                "allowed": self.allowed_options,
                "allowed_patterns": [],
            }, None),
        ])
Exemplo n.º 24
0
    def _test_cib_upgrade_promoted_max(self):
        (self.config.runner.cib.load(
            name="load_cib_old_version",
            filename="cib-empty-2.8.xml",
            before="runner.cib.load").runner.cib.upgrade(
                before="runner.cib.load").env.push_cib(resources="""
                    <resources>
                        <bundle id="B1">
                            <{container_type} image="pcs:test" promoted-max="0" />
                        </bundle>
                    </resources>
                """.format(container_type=self.container_type)))

        resource.bundle_create(self.env_assist.get_env(),
                               "B1",
                               self.container_type,
                               container_options={
                                   "image": "pcs:test",
                                   "promoted-max": "0",
                               })

        self.env_assist.assert_reports([
            (severities.INFO, report_codes.CIB_UPGRADE_SUCCESSFUL, {}, None),
        ])
Exemplo n.º 25
0
 def test_success(self):
     self.config.env.push_cib(resources="""
             <resources>
                 <bundle id="B1">
                     <docker image="pcs:test" />
                     <meta_attributes id="B1-meta_attributes">
                         <nvpair id="B1-meta_attributes-is-managed"
                             name="is-managed" value="false" />
                         <nvpair id="B1-meta_attributes-target-role"
                             name="target-role" value="Stopped" />
                     </meta_attributes>
                 </bundle>
             </resources>
         """)
     resource.bundle_create(self.env_assist.get_env(),
                            "B1",
                            "docker",
                            container_options={
                                "image": "pcs:test",
                            },
                            meta_attributes={
                                "target-role": "Stopped",
                                "is-managed": "false",
                            })
Exemplo n.º 26
0
 def test_empty_image(self):
     self.env_assist.assert_raise_library_error(
         lambda: resource.bundle_create(self.env_assist.get_env(),
                                        "B1",
                                        "docker",
                                        container_options={
                                            "image": "",
                                        },
                                        force_options=True),
         [
             (severities.ERROR, report_codes.INVALID_OPTION_VALUE, {
                 "option_name": "image",
                 "option_value": "",
                 "allowed_values": "image name",
             }, None),
         ])
Exemplo n.º 27
0
 def test_empty_image(self):
     self.runner.set_runs(
         fixture.call_cib_load(
             self.fixture_cib_resources(self.fixture_cib_pre)))
     assert_raise_library_error(
         lambda: resource.bundle_create(
             self.env, "B1", "docker", {
                 "image": "",
             }, force_options=True),
         (severities.ERROR, report_codes.INVALID_OPTION_VALUE, {
             "option_name": "image",
             "option_value": "",
             "allowed_values": "image name",
         }, None),
     )
     self.runner.assert_everything_launched()
Exemplo n.º 28
0
 def test_errors(self):
     self.config.remove("env.push_cib")
     self.env_assist.assert_raise_library_error(
         lambda: resource.bundle_create(self.env_assist.get_env(
         ), "B#1", "nonsense"), [
             (severities.ERROR, report_codes.INVALID_ID, {
                 "invalid_character": "#",
                 "id": "B#1",
                 "id_description": "bundle name",
                 "is_first_char": False,
             }, None),
             (severities.ERROR, report_codes.INVALID_OPTION_VALUE, {
                 "option_name": "container type",
                 "option_value": "nonsense",
                 "allowed_values": ("docker", ),
             }, None),
         ])
Exemplo n.º 29
0
 def test_options_errors(self):
     self.runner.set_runs(
         fixture.call_cib_load(
             self.fixture_cib_resources(self.fixture_cib_pre)))
     assert_raise_library_error(
         lambda: resource.bundle_create(
             self.env,
             "B1",
             "docker", {
                 "image": "pcs:test",
             },
             storage_map=[
                 {},
                 {
                     "id": "not#valid",
                     "source-dir": "/tmp/docker1a",
                     "source-dir-root": "/tmp/docker1b",
                     "target-dir": "/tmp/docker1c",
                 },
             ],
             force_options=True),
         # first
         (severities.ERROR,
          report_codes.REQUIRED_OPTION_OF_ALTERNATIVES_IS_MISSING, {
              "option_type": "storage-map",
              "option_names": ["source-dir", "source-dir-root"],
          }, None),
         (severities.ERROR, report_codes.REQUIRED_OPTION_IS_MISSING, {
             "option_type": "storage-map",
             "option_names": [
                 "target-dir",
             ],
         }, None),
         # second
         (severities.ERROR, report_codes.INVALID_ID, {
             "invalid_character": "#",
             "id": "not#valid",
             "id_description": "storage-map id",
             "is_first_char": False,
         }, None),
         (severities.ERROR, report_codes.MUTUALLY_EXCLUSIVE_OPTIONS, {
             "option_type": "storage-map",
             "option_names": ["source-dir", "source-dir-root"],
         }, None),
     )
Exemplo n.º 30
0
 def test_unknow_option(self):
     self.env_assist.assert_raise_library_error(
         lambda: resource.bundle_create(self.env_assist.get_env(),
                                        "B1",
                                        "docker",
                                        container_options={
                                            "image": "pcs:test",
                                            "extra": "option",
                                        }),
         [
             (severities.ERROR, report_codes.INVALID_OPTION, {
                 "option_names": [
                     "extra",
                 ],
                 "option_type": "container",
                 "allowed": self.allowed_options,
             }, report_codes.FORCE_OPTIONS),
         ])
Exemplo n.º 31
0
 def test_unknow_option(self):
     self.runner.set_runs(
         fixture.call_cib_load(
             self.fixture_cib_resources(self.fixture_cib_pre)))
     assert_raise_library_error(
         lambda: resource.bundle_create(self.env, "B1", "docker", {
             "image": "pcs:test",
             "extra": "option",
         }),
         (severities.ERROR, report_codes.INVALID_OPTION, {
             "option_names": [
                 "extra",
             ],
             "option_type": "container",
             "allowed": self.allowed_options,
         }, report_codes.FORCE_OPTIONS),
     )
     self.runner.assert_everything_launched()