def test_authorize_member(self): """ Test authorize member """ bootstrap = ZeroosBootstrap('bootstrap', data=self.valid_data) bootstrap._authorize_member(self.member) bootstrap._zt.client.network.updateMember.called_once_with( self.member, self.member['nodeId'], bootstrap.data['zerotierNetID'])
def test_add_node_install_error(self): """ Test adding a node that has state error during install """ with pytest.raises( RuntimeError, message= 'template should raise RuntimeError if task install has state error' ): self.member['online'] = True self.member['config']['authorized'] = False self.valid_data['wipeDisks'] = True bootstrap = ZeroosBootstrap('bootstrap', data=self.valid_data) bootstrap._authorize_member = MagicMock() bootstrap._wait_member_ip = MagicMock() node_sal = MagicMock(name='name') node_sal.client_info.os = MagicMock( return_value={'hostname': 'zero-os'}) bootstrap._get_node_sal = MagicMock(return_value=node_sal) bootstrap._ping_node = MagicMock() bootstrap.api.services.find = MagicMock(side_effect=[[], []]) node = MagicMock() task_install = MagicMock(state='error') node.schedule_action = MagicMock(return_value=task_install) bootstrap.api.services.create = MagicMock(return_value=node) bootstrap._add_node(self.member) node.delete.called_once_with()
def test_add_node(self): """ Test adding a node that doesn't exist in the services """ self.member['online'] = True self.member['config']['authorized'] = False self.valid_data['wipeDisks'] = True bootstrap = ZeroosBootstrap('bootstrap', data=self.valid_data) bootstrap._authorize_member = MagicMock() bootstrap._wait_member_ip = MagicMock() node_sal = MagicMock(name='name') node_sal.client_info.os = MagicMock( return_value={'hostname': 'zero-os'}) bootstrap._get_node_sal = MagicMock(return_value=node_sal) bootstrap._ping_node = MagicMock() erp = MagicMock() bootstrap.api.services.find = MagicMock(side_effect=[[], [], [erp]]) bootstrap.api.services.create = MagicMock() bootstrap._add_node(self.member) bootstrap._authorize_member.assert_called_once_with(self.member) bootstrap._zt.client.network.updateMember( self.member, self.member['nodeId'], bootstrap.data['zerotierNetID']) node_sal.wipedisks.assert_called_once_with() erp.schedule_action.assert_called_once_with( 'register', args={'node_name': node_sal.name})
def test_add_node_not_online(self): """ Test add a node that is not online """ self.member['online'] = False bootstrap = ZeroosBootstrap('bootstrap', data=self.valid_data) bootstrap._authorize_member = MagicMock() bootstrap._add_node(self.member) bootstrap._authorize_member.assert_not_called()
def test_add_node_not_authorized(self): """ Test add_node with node not authorized """ self.member['online'] = True self.member['config']['authorized'] = True bootstrap = ZeroosBootstrap('bootstrap', data=self.valid_data) bootstrap._authorize_member = MagicMock() bootstrap._add_node(self.member) bootstrap._authorize_member.assert_not_called()
def test_add_node_already_exists_install_not_ok(self): """ Test adding a node that already exists in the services but install state is not ok """ self.member['online'] = True self.member['config']['authorized'] = False bootstrap = ZeroosBootstrap('bootstrap', data=self.valid_data) bootstrap._authorize_member = MagicMock() bootstrap._wait_member_ip = MagicMock() bootstrap._get_node_sal = MagicMock() bootstrap._ping_node = MagicMock() hw = MagicMock() node = MagicMock() node.state.check.side_effect = StateCheckError bootstrap.api.services.find = MagicMock(side_effect=[[hw], [node], []]) bootstrap.api.services.create = MagicMock() bootstrap._add_node(self.member) assert node.delete.call_count == 1
def test_add_node_already_exists(self): """ Test adding a node that already exists in the services """ self.member['online'] = True self.member['config']['authorized'] = False bootstrap = ZeroosBootstrap('bootstrap', data=self.valid_data) bootstrap._authorize_member = MagicMock() bootstrap._wait_member_ip = MagicMock() bootstrap._get_node_sal = MagicMock() bootstrap._ping_node = MagicMock() hw = MagicMock() node = MagicMock() bootstrap.api.services.find = MagicMock(side_effect=[[hw], [node]]) bootstrap._add_node(self.member) bootstrap._authorize_member.assert_called_once_with(self.member) assert hw.schedule_action.call_count == 1 assert node.schedule_action.call_count == 1