コード例 #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_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
コード例 #4
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
コード例 #5
0
    def test_get_node_sal(self):
        """
        Test _get_node_sal
        """
        client = MagicMock()
        bootstrap = ZeroosBootstrap('bootstrap', data=self.valid_data)
        ip = '127.0.0.1'
        data = {
            'host': ip,
            'port': 6379,
            'password_': "",
            'db': 0,
            'ssl': True,
            'timeout': 120,
        }
        zero_os = patch('jumpscale.j.clients.zos.get',
                        MagicMock(return_value=client)).start()
        node = bootstrap._get_node_sal(ip)

        zero_os.called_once_with(instance='bootstrap',
                                 data=data,
                                 create=True,
                                 die=True)
        assert node == client