Exemple #1
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()
Exemple #2
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),
     )
Exemple #3
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),
     )
Exemple #4
0
    def test_nonexistent_resource(self):
        self.runner.set_runs(
            fixture.call_cib_load(
                fixture.cib_resources(fixture_primitive_cib_unmanaged)))

        assert_raise_library_error(lambda: resource.manage(self.env, ["B"]),
                                   fixture.report_not_found("B", "resources"))
        self.runner.assert_everything_launched()
Exemple #5
0
    def test_bundle(self):
        self.runner.set_runs(
            fixture.call_cib_load(
                fixture.cib_resources(fixture_bundle_cib_unmanaged_primitive)))

        assert_raise_library_error(
            lambda: resource.manage(self.env, ["A-bundle"], False),
            fixture.report_not_for_bundles("A-bundle"))
        self.runner.assert_everything_launched()
Exemple #6
0
    def test_bad_resource_enable(self):
        self.runner.set_runs(
            fixture.call_cib_load(
                fixture.cib_resources(self.fixture_cib_unmanaged)))

        assert_raise_library_error(
            lambda: resource.manage(self.env, ["B", "X", "Y", "A"]),
            fixture.report_not_found("X", "resources"),
            fixture.report_not_found("Y", "resources"),
        )
        self.runner.assert_everything_launched()
Exemple #7
0
 def test_nonexisting_id(self):
     fixture_cib_pre = "<resources />"
     self.runner.set_runs(
         fixture.call_cib_load(self.fixture_cib_resources(fixture_cib_pre)))
     assert_raise_library_error(
         lambda: resource.bundle_update(self.env, "B1"),
         (severities.ERROR, report_codes.ID_NOT_FOUND, {
             "id": "B1",
             "id_description": "bundle",
             "context_type": "resources",
             "context_id": "",
         }, None),
     )
     self.runner.assert_everything_launched()
Exemple #8
0
 def test_bundle_doesnt_exist(self):
     self.runner.set_runs(fixture_agent_load_calls() +
                          fixture.call_cib_load(
                              fixture.cib_resources(
                                  self.fixture_empty_resources,
                                  self.upgraded_cib,
                              )))
     assert_raise_library_error(
         self.simplest_create,
         (severities.ERROR, report_codes.ID_NOT_FOUND, {
             "id": "B",
             "id_description": "bundle",
             "context_type": "resources",
             "context_id": "",
         }))
Exemple #9
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()
Exemple #10
0
 def test_id_not_bundle(self):
     resources_pre_update = """<resources>
         <primitive id="B"/>
     </resources>"""
     self.runner.set_runs(fixture_agent_load_calls() +
                          fixture.call_cib_load(
                              fixture.cib_resources(
                                  resources_pre_update,
                                  self.upgraded_cib,
                              )))
     assert_raise_library_error(
         self.simplest_create,
         (severities.ERROR, report_codes.ID_BELONGS_TO_UNEXPECTED_TYPE, {
             "id": "B",
             "expected_types": ["bundle"],
             "current_type": "primitive",
         }))
Exemple #11
0
 def test_remove_missing(self):
     self.runner.set_runs(
         fixture.call_cib_load(
             self.fixture_cib_resources(self.fixture_cib_storage_1)))
     assert_raise_library_error(
         lambda: resource.bundle_update(
             self.env, "B1", storage_map_remove=[
                 "B1-storage-map-1",
             ]),
         (severities.ERROR, report_codes.ID_NOT_FOUND, {
             "id": "B1-storage-map-1",
             "id_description": "storage-map",
             "context_type": "bundle",
             "context_id": "B1",
         }, None),
     )
     self.runner.assert_everything_launched()
Exemple #12
0
 def test_not_bundle_id(self):
     fixture_cib_pre = """
         <resources>
             <primitive id="B1" />
         </resources>
     """
     self.runner.set_runs(
         fixture.call_cib_load(self.fixture_cib_resources(fixture_cib_pre)))
     assert_raise_library_error(
         lambda: resource.bundle_update(self.env, "B1"),
         (severities.ERROR, report_codes.ID_BELONGS_TO_UNEXPECTED_TYPE, {
             "id": "B1",
             "expected_types": ["bundle"],
             "current_type": "primitive",
         }, None),
     )
     self.runner.assert_everything_launched()
Exemple #13
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),
     )
Exemple #14
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()
Exemple #15
0
 def test_unknow_option(self):
     self.runner.set_runs(
         fixture.call_cib_load(
             self.fixture_cib_resources(self.fixture_cib_interface)))
     assert_raise_library_error(
         lambda: resource.bundle_update(
             self.env, "B1", network_options={
                 "extra": "option",
             }),
         (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()
Exemple #16
0
 def test_bundle_not_empty(self):
     resources_pre_update = """<resources>
         <bundle id="B">
             <primitive id="P"/>
         </bundle>
     </resources>"""
     self.runner.set_runs(fixture_agent_load_calls() +
                          fixture.call_cib_load(
                              fixture.cib_resources(
                                  resources_pre_update,
                                  self.upgraded_cib,
                              )))
     assert_raise_library_error(
         self.simplest_create,
         (severities.ERROR,
          report_codes.RESOURCE_BUNDLE_ALREADY_CONTAINS_A_RESOURCE, {
              "bundle_id": "B",
              "resource_id": "P",
          }))
Exemple #17
0
 def test_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, "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),
     )
     self.runner.assert_everything_launched()
Exemple #18
0
 def test_cannot_remove_required_options(self):
     self.runner.set_runs(
         fixture.call_cib_load(
             self.fixture_cib_resources(self.fixture_cib_minimal)))
     assert_raise_library_error(
         lambda: resource.bundle_update(self.env,
                                        "B1",
                                        container_options={
                                            "image": "",
                                            "options": "test",
                                        },
                                        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()
Exemple #19
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",
                                        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),
     )
     self.runner.assert_everything_launched()
Exemple #20
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",
                                        },
                                        port_map=[
                                            {},
                                            {
                                                "id": "not#valid",
                                            },
                                            {
                                                "internal-port": "1000",
                                            },
                                            {
                                                "port": "abc",
                                            },
                                            {
                                                "port": "2000",
                                                "range": "3000-4000",
                                                "internal-port": "def",
                                            },
                                        ],
                                        force_options=True),
         # first
         (severities.ERROR,
          report_codes.REQUIRED_OPTION_OF_ALTERNATIVES_IS_MISSING, {
              "option_type": "port-map",
              "option_names": ["port", "range"],
          }, None),
         # second
         (severities.ERROR, report_codes.INVALID_ID, {
             "invalid_character": "#",
             "id": "not#valid",
             "id_description": "port-map id",
             "is_first_char": False,
         }, None),
         (severities.ERROR,
          report_codes.REQUIRED_OPTION_OF_ALTERNATIVES_IS_MISSING, {
              "option_type": "port-map",
              "option_names": ["port", "range"],
          }, None),
         # third
         (severities.ERROR, report_codes.PREREQUISITE_OPTION_IS_MISSING, {
             "option_type": "port-map",
             "option_name": "internal-port",
             "prerequisite_type": "port-map",
             "prerequisite_name": "port",
         }, None),
         (severities.ERROR,
          report_codes.REQUIRED_OPTION_OF_ALTERNATIVES_IS_MISSING, {
              "option_type": "port-map",
              "option_names": ["port", "range"],
          }, None),
         # fourth
         (severities.ERROR, report_codes.INVALID_OPTION_VALUE, {
             "option_name": "port",
             "option_value": "abc",
             "allowed_values": "a port number (1-65535)",
         }, None),
         # fifth
         (severities.ERROR, report_codes.MUTUALLY_EXCLUSIVE_OPTIONS, {
             "option_names": [
                 "port",
                 "range",
             ],
             "option_type": "port-map",
         }, None),
         (severities.ERROR, report_codes.INVALID_OPTION_VALUE, {
             "option_name": "internal-port",
             "option_value": "def",
             "allowed_values": "a port number (1-65535)",
         }, None),
     )
     self.runner.assert_everything_launched()