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)
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 )
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()
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), )
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()
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), ])
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), )
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> """)
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), ])
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> """)
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), ])
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), ])
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), ])
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> """)
def simple_bundle_create(self, wait=False): return resource.bundle_create( self.env, "B1", "docker", {"image": "pcs:test"}, wait=wait, )
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, )
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), ])
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)
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)
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)
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), ])
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", }, ])
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), ])
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), ])
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", })
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), ])
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()
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), ])
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), )
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), ])
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()