def test_remove_ip_remove_port_force(self): (self.config.runner.cib.load( resources=self.fixture_resources_pre.format(network=""" <network ip-range-start="192.168.100.200" control-port="1234" /> """)).env.push_cib( resources=self.fixture_resources_pre.format(network=''))) resource.bundle_update( self.env_assist.get_env(), "B1", network_options={ "ip-range-start": "", "control-port": "", }, force_options=True, ) self.env_assist.assert_reports([ fixture.warn( report_codes.RESOURCE_IN_BUNDLE_NOT_ACCESSIBLE, bundle_id="B1", inner_resource_id="P", ) ])
def test_keep_network_when_port_map_set(self): (self.config.runner.cib.load(resources=""" <resources> <bundle id="B1"> <docker image="pcs:test" /> <network host-interface="eth0"> <something /> </network> </bundle> </resources> """).env.push_cib(resources=""" <resources> <bundle id="B1"> <docker image="pcs:test" /> <network> <something /> </network> </bundle> </resources> """)) resource.bundle_update(self.env_assist.get_env(), "B1", network_options={ "host-interface": "", })
def test_add_network(self): (self.config.runner.cib.load( resources=fixture_resources_minimal).env.push_cib( resources=self.fixture_cib_interface)) resource.bundle_update(self.env_assist.get_env(), "B1", network_options={ "host-interface": "eth0", })
def test_unknown_option_remove(self): (self.config.runner.cib.load( resources=self.fixture_cib_extra_option).env.push_cib( resources=self.fixture_cib_interface)) resource.bundle_update(self.env_assist.get_env(), "B1", network_options={ "extra": "", })
def test_add(self): (self.config.runner.cib.load( resources=self.fixture_cib_port_80).env.push_cib( resources=self.fixture_cib_port_80_8080)) resource.bundle_update(self.env_assist.get_env(), "B1", port_map_add=[{ "port": "8080", }])
def test_remove(self): (self.config.runner.cib.load( resources=self.fixture_cib_port_80_8080).env.push_cib( resources=self.fixture_cib_port_80)) resource.bundle_update(self.env_assist.get_env(), "B1", port_map_remove=[ "B1-port-map-8080", ])
def test_remove_storage(self): (self.config.runner.cib.load( resources=self.fixture_cib_storage_1).env.push_cib( resources=fixture_resources_minimal)) resource.bundle_update(self.env_assist.get_env(), "B1", storage_map_remove=[ "B1-storage-map", ])
def test_remove_meta_element(self): (self.config.runner.cib.load( resources=self.fixture_meta_stopped).env.push_cib( resources=self.fixture_no_meta)) resource.bundle_update(self.env_assist.get_env(), "B1", meta_attributes={ "target-role": "", })
def test_no_updates(self): (self.config.runner.cib.load(resources=""" <resources> <bundle id="B1"> <docker image="pcs:test" /> </bundle> </resources> """).env.push_cib()) resource.bundle_update(self.env_assist.get_env(), "B1")
def test_add(self): (self.config.runner.cib.load( resources=self.fixture_cib_storage_1).env.push_cib( resources=self.fixture_cib_storage_1_2)) resource.bundle_update(self.env_assist.get_env(), "B1", storage_map_add=[{ "source-dir": "/tmp/docker2a", "target-dir": "/tmp/docker2b", }])
def test_unknown_option_remove(self): (self.config.runner.cib.load( resources=self.fixture_cib_extra_option).env.push_cib( resources=fixture_resources_minimal)) resource.bundle_update(self.env_assist.get_env(), "B1", container_options={ "extra": "", }, force_options=True)
def test_already_not_accessible(self): (self.config.runner.cib.load( resources=self.fixture_resources_pre.format( network="")).env.push_cib( resources=self.fixture_resources_pre.format( network='<network host-interface="int"/>'))) resource.bundle_update(self.env_assist.get_env(), "B1", network_options={ "host-interface": "int", })
def test_remove_ip_add_port(self): (self.config.runner.cib.load( resources=self.fixture_resources_pre.format( network='<network ip-range-start="192.168.100.200"/>')).env. push_cib(resources=self.fixture_resources_pre.format( network='<network control-port="1234"/>'))) resource.bundle_update(self.env_assist.get_env(), "B1", network_options={ "ip-range-start": "", "control-port": "1234", })
def test_cib_upgrade(self): (self.config.runner.cib.load( filename="cib-empty.xml", name="load_cib_old_version").runner.cib.upgrade().runner.cib.load( resources=""" <resources> <bundle id="B1"> <docker image="pcs:test" /> </bundle> </resources> """).env.push_cib()) resource.bundle_update(self.env_assist.get_env(), "B1") self.env_assist.assert_reports([ (severities.INFO, report_codes.CIB_UPGRADE_SUCCESSFUL, {}, None), ])
def test_success(self): fixture_cib_pre = """ <resources> <bundle id="B1"> <docker image="pcs:test" /> <network host-interface="eth0" control-port="12345" /> </bundle> </resources> """ fixture_cib_post = """ <resources> <bundle id="B1"> <docker image="pcs:test" /> <network host-interface="eth0" host-netmask="24" /> </bundle> </resources> """ self.assert_command_effect( fixture_cib_pre, lambda: resource.bundle_update(self.env, "B1", network_options={ "control-port": "", "host-netmask": "24", }), fixture_cib_post)
def test_keep_network_when_port_map_set(self): fixture_cib_pre = """ <resources> <bundle id="B1"> <docker image="pcs:test" /> <network host-interface="eth0"> <something /> </network> </bundle> </resources> """ fixture_cib_post = """ <resources> <bundle id="B1"> <docker image="pcs:test" /> <network> <something /> </network> </bundle> </resources> """ self.assert_command_effect( fixture_cib_pre, lambda: resource.bundle_update( self.env, "B1", network_options={ "host-interface": "", }), fixture_cib_post)
def simple_bundle_update(self, wait=False): return resource.bundle_update( self.env, "B1", {"image": "new:image"}, wait=wait, )
def test_add(self): self.assert_command_effect( self.fixture_cib_storage_1, lambda: resource.bundle_update( self.env, "B1", storage_map_add=[{ "source-dir": "/tmp/docker2a", "target-dir": "/tmp/docker2b", }]), self.fixture_cib_storage_1_2)
def test_unknown_option_remove(self): self.assert_command_effect( self.fixture_cib_extra_option, lambda: resource.bundle_update( self.env, "B1", network_options={ "extra": "", }), self.fixture_cib_interface, )
def test_unknown_option_remove(self): self.assert_command_effect( self.fixture_cib_extra_option, lambda: resource.bundle_update( self.env, "B1", container_options={ "extra": "", }), self.fixture_cib_minimal, )
def test_unknow_option_forced(self): (self.config.runner.cib.load( resources=self.fixture_cib_interface).env.push_cib( resources=self.fixture_cib_extra_option)) resource.bundle_update(self.env_assist.get_env(), "B1", network_options={ "extra": "option", }, force_options=True) self.env_assist.assert_reports([ (severities.WARNING, report_codes.INVALID_OPTION, { "option_names": [ "extra", ], "option_type": "network", "allowed": self.allowed_options, }, None), ])
def test_no_updates(self): fixture_cib_pre = """ <resources> <bundle id="B1"> <docker image="pcs:test" /> </bundle> </resources> """ self.assert_command_effect( fixture_cib_pre, lambda: resource.bundle_update(self.env, "B1"), fixture_cib_pre)
def test_cib_upgrade(self): fixture_cib_pre = """ <resources> <bundle id="B1"> <docker image="pcs:test" /> </bundle> </resources> """ self.runner.set_runs( fixture.calls_cib_load_and_upgrade(fixture_cib_pre) + fixture.calls_cib(fixture_cib_pre, fixture_cib_pre, cib_base_file=self.cib_base_file)) resource.bundle_update(self.env, "B1") self.env.report_processor.assert_reports([ (severities.INFO, report_codes.CIB_UPGRADE_SUCCESSFUL, {}, None), ]) self.runner.assert_everything_launched()
def test_nonexisting_id(self): self.config.runner.cib.load() self.env_assist.assert_raise_library_error( lambda: resource.bundle_update(self.env_assist.get_env(), "B1"), [ (severities.ERROR, report_codes.ID_NOT_FOUND, { "id": "B1", "id_description": "bundle", "context_type": "resources", "context_id": "", }, None), ], expected_in_processor=False)
def test_change_meta(self): fixture_cib_pre = """ <resources> <bundle id="B1"> <meta_attributes id="B1-meta_attributes"> <nvpair id="B1-meta_attributes-target-role" name="target-role" value="Stopped" /> <nvpair id="B1-meta_attributes-priority" name="priority" value="15" /> <nvpair id="B1-meta_attributes-is-managed" name="is-managed" value="false" /> </meta_attributes> <docker image="pcs:test" masters="3" replicas="6"/> </bundle> </resources> """ fixture_cib_post = """ <resources> <bundle id="B1"> <meta_attributes id="B1-meta_attributes"> <nvpair id="B1-meta_attributes-target-role" name="target-role" value="Stopped" /> <nvpair id="B1-meta_attributes-priority" name="priority" value="10" /> <nvpair id="B1-meta_attributes-resource-stickiness" name="resource-stickiness" value="100" /> </meta_attributes> <docker image="pcs:test" masters="3" replicas="6"/> </bundle> </resources> """ (self.config.runner.cib.load(resources=fixture_cib_pre).env.push_cib( resources=fixture_cib_post)) resource.bundle_update(self.env_assist.get_env(), "B1", meta_attributes={ "priority": "10", "resource-stickiness": "100", "is-managed": "", })
def test_success(self): (self.config.runner.cib.load(resources=""" <resources> <bundle id="B1"> <docker image="pcs:test" masters="3" replicas="6"/> </bundle> </resources> """).env.push_cib(resources=""" <resources> <bundle id="B1"> <docker image="pcs:test" options="test" replicas="3" /> </bundle> </resources> """)) resource.bundle_update(self.env_assist.get_env(), "B1", container_options={ "options": "test", "replicas": "3", "masters": "", })
def test_remove_missing(self): (self.config.runner.cib.load(resources=self.fixture_cib_storage_1)) self.env_assist.assert_raise_library_error( lambda: resource.bundle_update(self.env_assist.get_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)])
def test_success(self): (self.config.runner.cib.load(resources=""" <resources> <bundle id="B1"> <docker image="pcs:test" /> <network host-interface="eth0" control-port="12345" /> </bundle> </resources> """).env.push_cib(resources=""" <resources> <bundle id="B1"> <docker image="pcs:test" /> <network host-interface="eth0" host-netmask="24" /> </bundle> </resources> """)) resource.bundle_update(self.env_assist.get_env(), "B1", network_options={ "control-port": "", "host-netmask": "24", })
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()
def test_keep_network_when_options_set(self): (self.config.runner.cib.load(resources=""" <resources> <bundle id="B1"> <docker image="pcs:test" /> <network host-interface="eth0"> <port-mapping id="B1-port-map-80" port="80" /> </network> </bundle> </resources> """).env.push_cib(resources=""" <resources> <bundle id="B1"> <docker image="pcs:test" /> <network host-interface="eth0" /> </bundle> </resources> """)) resource.bundle_update(self.env_assist.get_env(), "B1", port_map_remove=[ "B1-port-map-80", ])