Пример #1
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()
Пример #2
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})
Пример #3
0
    def test_wait_member_ip(self):
        """
        Test _wait_member_ip
        """
        patch("zerorobot.template.decorator.timeout").start()
        bootstrap = ZeroosBootstrap('bootstrap', data=self.valid_data)

        resp = MagicMock()
        resp.json = MagicMock(return_value=self.member)
        resp2 = MagicMock()
        resp2.json = MagicMock(return_value=self.member2)
        bootstrap._zt.client.network.getMember = MagicMock(
            side_effect=[resp, resp2])
        zerotier_ip = bootstrap._wait_member_ip(self.member)

        assert zerotier_ip == '127.0.0.1'
        assert bootstrap._zt.client.network.getMember.call_count == 2
Пример #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
Пример #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