def test_existing_attrs(self, mock_get_node): mock_get_node.return_value = self.node2 node.update_node_instance_attrs( self.cib, self.id_provider, "rh73-node2", { "a": "", "b": "b", "x": "X" }, state_nodes=self.state, ) assert_xml_equal( etree_to_str(self.node2), """ <node id="2" uname="rh73-node2"> <instance_attributes id="nodes-2"> <nvpair name="b" value="b" /> <nvpair name="c" value="C" /> <nvpair id="nodes-2-x" name="x" value="X" /> </instance_attributes> </node> """, )
def test_keep_empty_nvset_and_node(self, mock_get_node): mock_get_node.return_value = self.node2 node.update_node_instance_attrs( self.cib, self.id_provider, "rh73-node2", { "a": "", "b": "", "c": "" }, state_nodes=self.state, ) assert_xml_equal( self.compile_cib( self.node1, """ <node id="2" uname="rh73-node2"> <instance_attributes id="nodes-2" /> </node> """, self.node3, ), self.compile_cib(self.node1, self.node2, self.node3), )
def test_dont_create_empty_nvset_if_no_attrs(self, mock_get_node): mock_get_node.return_value = self.node1 node.update_node_instance_attrs( self.cib, self.id_provider, "rh73-node1", {}, state_nodes=self.state ) assert_xml_equal( etree_to_str(self.node1), """<node id="1" uname="rh73-node1" />""" )
def _set_instance_attrs_all_nodes(lib_env, attrs, wait): with cib_runner_nodes(lib_env, wait) as (cib, dummy_runner, state_nodes): for node in [node.attrs.name for node in state_nodes]: update_node_instance_attrs(cib, IdProvider(cib), node, attrs, state_nodes=state_nodes)
def _set_instance_attrs_local_node(lib_env, attrs, wait): if not lib_env.is_cib_live: # If we are not working with a live cluster we cannot get the local node # name. raise LibraryError(reports.live_environment_required_for_local_node()) with cib_runner_nodes(lib_env, wait) as (cib, runner, state_nodes): update_node_instance_attrs(cib, get_local_node_name(runner), attrs, state_nodes)
def test_dont_create_empty_node_if_deleting(self, mock_get_node): node4 = etree.fromstring("""<node id="4" />""") mock_get_node.return_value = node4 node.update_node_instance_attrs(self.cib, self.id_provider, "rh73-node4", {"x": ""}, state_nodes=self.state) assert_xml_equal(etree_to_str(self.cib), self.compile_cib(self.node1, self.node2, self.node3))
def _set_instance_attrs_all_nodes(lib_env, attrs, wait): with cib_runner_nodes(lib_env, wait) as (cib, dummy_runner, state_nodes): for node in [node.attrs.name for node in state_nodes]: update_node_instance_attrs( cib, IdProvider(cib), node, attrs, state_nodes=state_nodes )
def test_empty_node(self, mock_get_node): mock_get_node.return_value = self.node1 node.update_node_instance_attrs(self.cib, "rh73-node1", {"x": "X"}, self.state) assert_xml_equal( etree_to_str(self.node1), """ <node id="1" uname="rh73-node1"> <instance_attributes id="nodes-1"> <nvpair id="nodes-1-x" name="x" value="X" /> </instance_attributes> </node> """)
def _set_instance_attrs_node_list(lib_env, attrs, node_names, wait): with cib_runner_nodes(lib_env, wait) as (cib, dummy_runner, state_nodes): known_nodes = [node.attrs.name for node in state_nodes] report = [] for node in node_names: if node not in known_nodes: report.append(reports.node_not_found(node)) if report: raise LibraryError(*report) for node in node_names: update_node_instance_attrs(cib, node, attrs, state_nodes)
def _set_instance_attrs_local_node(lib_env, attrs, wait): if not lib_env.is_cib_live: # If we are not working with a live cluster we cannot get the local node # name. raise LibraryError(reports.live_environment_required_for_local_node()) with cib_runner_nodes(lib_env, wait) as (cib, runner, state_nodes): update_node_instance_attrs( cib, get_local_node_name(runner), attrs, state_nodes )
def test_empty_node(self, mock_get_node): mock_get_node.return_value = self.node1 node.update_node_instance_attrs( self.cib, "rh73-node1", {"x": "X"}, self.state ) assert_xml_equal( etree_to_str(self.node1), """ <node id="1" uname="rh73-node1"> <instance_attributes id="nodes-1"> <nvpair id="nodes-1-x" name="x" value="X" /> </instance_attributes> </node> """ )
def _set_instance_attrs_local_node(lib_env, attrs, wait): if not lib_env.is_cib_live: # If we are not working with a live cluster we cannot get the local node # name. raise LibraryError( ReportItem.error( reports.messages.LiveEnvironmentRequiredForLocalNode())) with cib_runner_nodes(lib_env, wait) as (cib, runner, state_nodes): update_node_instance_attrs( cib, IdProvider(cib), get_local_node_name(runner), attrs, state_nodes=state_nodes, )
def test_multiple_attrs_sets(self, mock_get_node): mock_get_node.return_value = self.node3 node.update_node_instance_attrs(self.cib, "rh73-node3", {"x": "X"}, self.state) assert_xml_equal( etree_to_str(self.node3), """ <node id="3" uname="rh73-node3" > <instance_attributes id="nodes-3-a"> <nvpair name="a" value="A" /> <nvpair id="nodes-3-a-x" name="x" value="X" /> </instance_attributes> <instance_attributes id="nodes-3-b"> <nvpair name="b" value="B" /> </instance_attributes> </node> """)
def test_exisitng_attrs(self, mock_get_node): mock_get_node.return_value = self.node2 node.update_node_instance_attrs( self.cib, "rh73-node2", {"a": "", "b": "b", "x": "X"}, self.state ) assert_xml_equal( etree_to_str(self.node2), """ <node id="2" uname="rh73-node2"> <instance_attributes id="nodes-2"> <nvpair name="b" value="b" /> <nvpair name="c" value="C" /> <nvpair id="nodes-2-x" name="x" value="X" /> </instance_attributes> </node> """ )
def _set_instance_attrs_node_list(lib_env, attrs, node_names, wait): with cib_runner_nodes(lib_env, wait) as (cib, dummy_runner, state_nodes): known_nodes = [node.attrs.name for node in state_nodes] report_list = [] for node in node_names: if node not in known_nodes: report_list.append( ReportItem.error(reports.messages.NodeNotFound(node))) if report_list: raise LibraryError(*report_list) for node in node_names: update_node_instance_attrs(cib, IdProvider(cib), node, attrs, state_nodes=state_nodes)
def test_multiple_attrs_sets(self, mock_get_node): mock_get_node.return_value = self.node3 node.update_node_instance_attrs( self.cib, "rh73-node3", {"x": "X"}, self.state ) assert_xml_equal( etree_to_str(self.node3), """ <node id="3" uname="rh73-node3" > <instance_attributes id="nodes-3-a"> <nvpair name="a" value="A" /> <nvpair id="nodes-3-a-x" name="x" value="X" /> </instance_attributes> <instance_attributes id="nodes-3-b"> <nvpair name="b" value="B" /> </instance_attributes> </node> """ )