Beispiel #1
0
    def test_ping_node(self):
        """
        Test ping node
        """
        patch("zerorobot.template.decorator.timeout").start()
        bootstrap = ZeroosBootstrap('bootstrap', data=self.valid_data)
        bootstrap.logger = MagicMock()
        node_sal = MagicMock()
        node_sal.client.ping = MagicMock(side_effect=[Exception, True])
        bootstrap._ping_node(node_sal, MagicMock())

        # ensure the loop is working when ping raises an exception
        assert node_sal.client.ping.call_count == 2
Beispiel #2
0
    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()
Beispiel #3
0
    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})
Beispiel #4
0
    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
Beispiel #5
0
    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