コード例 #1
0
    def test_namespace_info(self):
        """
        Test namespace_info action
        """
        self.valid_data['namespaces'].append({'name': 'namespace', 'size': 20, 'public': True, 'password': ''})

        zdb = Zerodb('zdb', data=self.valid_data)
        info_dict = {
            'data_limits_bytes': 21474836480,
            'data_size_bytes': 0,
            'data_size_mb': 0.0,
            'entries': 0,
            'index_size_bytes': 0,
            'index_size_kb': 0.0,
            'name': 'two',
            'password': '******',
            'public': 'yes'
        }
        zdb.state.set('status', 'running', 'ok')
        namespace = MagicMock()
        namespace.info.return_value.to_dict.return_value = info_dict
        zdb_sal = MagicMock(namespaces={'namespace': namespace})
        zdb._node_sal.primitives.from_dict.return_value = zdb_sal

        assert zdb.namespace_info('namespace') == info_dict
コード例 #2
0
 def test_namespace_exist_update_delete_exists(self):
     """
     Test _namespace_exists_update_delete if namespace exists
     """
     self.valid_data['namespaces'].append({'name': 'namespace', 'size': 20, 'public': True, 'password': ''})
     zdb = Zerodb('zdb', data=self.valid_data)
     assert zdb._namespace_exists_update_delete('namespace') is True
コード例 #3
0
 def test_namespace_exist_update_delete_runtimeerror(self):
     """
     Test _namespace_exists_update_delete raises RunTimeError if you try to update and delete a namespace at the same time
     """
     with pytest.raises(ValueError,
                        message='_namespace_exist_update_delete action should raise an error if user is trying to set property and delete namespace'):
         zdb = Zerodb('zdb', data=self.valid_data)
         zdb._namespace_exists_update_delete('namespace', prop='password', delete=True)
コード例 #4
0
 def test_start_before_install(self):
     """
     Test start action without installing
     """
     with pytest.raises(StateCheckError,
                        message='start action should raise an error if zerodb is not installed'):
         zdb = Zerodb('zdb', data=self.valid_data)
         zdb.start()
コード例 #5
0
 def test_namespace_list(self):
     """
     Test namespace_list action
     """
     zdb = Zerodb('zdb', data=self.valid_data)
     zdb.state.set('status', 'running', 'ok')
     namespaces = zdb.namespace_list()
     assert namespaces == zdb.data['namespaces']
コード例 #6
0
 def test_namespace_exist_update_delete_invalid_property(self):
     """
     Test _namespace_exists_update_delete raises ValueError if you supply invalid prop
     """
     with pytest.raises(ValueError,
                        message='_namespace_exist_update_dekete action should raise an error if user uses invalid prop'):
         zdb = Zerodb('zdb', data=self.valid_data)
         zdb._namespace_exists_update_delete('namespace', prop='prop')
コード例 #7
0
 def test_namespace_exist_update_delete_update_prop(self):
     """
     Test _namespace_exists_update_delete if namespace exists and prop is updated
     """
     self.valid_data['namespaces'].append({'name': 'namespace', 'size': 20, 'public': True, 'password': ''})
     zdb = Zerodb('zdb', data=self.valid_data)
     assert zdb._namespace_exists_update_delete('namespace', prop='size', value=30) is True
     assert zdb.data['namespaces'] == [{'name': 'namespace', 'size': 30, 'public': True, 'password': ''}]
コード例 #8
0
 def test_namespace_private_url_before_start(self):
     """
     Test namespace_private_url action without start
     """
     with pytest.raises(StateCheckError,
                        message='namespace action should raise an error if zerodb is not started'):
         zdb = Zerodb('zdb', data=self.valid_data)
         zdb.namespace_private_url('namespace')
コード例 #9
0
 def test_namespace_private_url_doesnt_exist(self):
     """
     Test namespace_private_url action without start
     """
     with pytest.raises(LookupError,
                        message='namespace action should raise an error if namespace doesnt exist'):
         zdb = Zerodb('zdb', data=self.valid_data)
         zdb.state.set('status', 'running', 'ok')
         zdb.namespace_private_url('namespace')
コード例 #10
0
 def test_namespace_set_namespace_doesnt_exist(self):
     """
     Test namespace_set action if namespace doesn't exist
     """
     with pytest.raises(LookupError,
                        message='namespace_set action should raise an error if namespace doesn\'t exists'):
         zdb = Zerodb('zdb', data=self.valid_data)
         zdb.state.set('status', 'running', 'ok')
         zdb._namespace_exists_update_delete = MagicMock(return_value=False)
         zdb.namespace_set('namespace', 'size', 12)
コード例 #11
0
    def test_deploy(self):
        """
        Test _deploy helper function
        """
        zdb = Zerodb('zdb', data=self.valid_data)
        zdb_sal = MagicMock(zt_identity='identity')

        zdb._node_sal.primitives.from_dict.return_value = zdb_sal
        zdb._deploy()
        assert zdb.data['ztIdentity'] == zdb_sal.zt_identity
コード例 #12
0
 def test_monitor_not_started(self):
     """
     Test _monitor action when zerodb is not started
     """
     zdb = Zerodb('zdb', data=self.valid_data)
     zdb.state.set('actions', 'install', 'ok')
     with pytest.raises(StateCheckError, message='_monitor should not start zerodb is the start action has not been called'):
         zdb._monitor()
     with pytest.raises(StateCheckError, message='_monitor should not start zerodb is the start action has not been called'):
         zdb.state.check('status', 'running', 'ok')
コード例 #13
0
    def test_stop(self):
        """
        Test stop action
        """
        zdb = Zerodb('zdb', data=self.valid_data)
        zdb.state.set('actions', 'install', 'ok')
        zdb.api.services.get = MagicMock()
        zdb.stop()

        zdb._zerodb_sal.stop.assert_called_once_with()
コード例 #14
0
    def test_install_empty_password(self):
        """
        Test install action sets admin password if empty
        """
        zdb = Zerodb('zdb', data=self.valid_data)

        zdb.install()
        zdb._zerodb_sal.deploy.called_once_with()
        zdb.state.check('actions', 'install', 'ok')
        assert zdb.data['admin'] != ''
コード例 #15
0
    def test_namespace_info(self):
        """
        Test namespace_info action
        """
        zdb = Zerodb('zdb', data=self.valid_data)
        zdb.state.set('actions', 'start', 'ok')
        zdb.api.services.get = MagicMock()
        zdb.namespace_info('namespace')

        zdb._zerodb_sal.get_namespace_info.assert_called_once_with('namespace')
コード例 #16
0
 def test_install_empty_path(self):
     """
     Test install action sets path if empty
     """
     data = self.valid_data.copy()
     data['path'] = ''
     zdb = Zerodb('zdb', data=data)
     zdb.api = MagicMock()
     zdb.api.services.get.return_value.schedule_action.return_value.wait.return_value.result = 'path', 'name'
     zdb.install()
     assert zdb.data['path'] == 'path'
コード例 #17
0
ファイル: zerodb_test.py プロジェクト: BolaNasr/0-templates-1
 def test_connection_info(self):
     """
     Test connection_info action
     """
     zdb = Zerodb('zdb', data=self.valid_data)
     node_sal = MagicMock(public_addr='127.0.0.1')
     patch('js9.j.clients.zos.sal.get_node',
           MagicMock(return_value=node_sal)).start()
     assert zdb.connection_info() == {
         'ip': node_sal.public_addr,
         'port': zdb.data['nodePort'],
     }
コード例 #18
0
    def test_stop(self):
        """
        Test stop action
        """
        zdb = Zerodb('zdb', data=self.valid_data)
        zdb.stop()

        zdb._zerodb_sal.stop.assert_called_once_with()
        with pytest.raises(StateCheckError, message='state status/running should not be present after stop'):
            zdb.state.check('status', 'running', 'ok')
        with pytest.raises(StateCheckError, message='state action/install should not be present after stop'):
            zdb.state.check('actions', 'start', 'ok')
コード例 #19
0
 def test_connection_info(self):
     """
     Test connection_info action
     """
     zdb = Zerodb('zdb', data=self.valid_data)
     node = MagicMock( public_addr='127.0.0.1', storageAddr='127.0.0.1')
     zdb_sal = MagicMock(node_port=9000, node=node)
     zdb._node_sal.primitives.from_dict.return_value = zdb_sal
     assert zdb.connection_info() == {
         'ip': zdb_sal.node.public_addr,
         'port': zdb.data['nodePort'],
     }
コード例 #20
0
    def test_namespace_private_url(self):
        """
        Test namespace_url action
        """
        self.valid_data['namespaces'].append({'name': 'namespace', 'size': 20, 'public': True, 'password': ''})

        zdb = Zerodb('zdb', data=self.valid_data)
        zdb.state.set('status', 'running', 'ok')
        namespace = MagicMock(private_url='url')
        zdb_sal = MagicMock(namespaces={'namespace': namespace})
        zdb._node_sal.primitives.from_dict.return_value = zdb_sal

        assert zdb.namespace_private_url('namespace') == 'url'
コード例 #21
0
    def test_install_with_password(self):
        """
        Test install action with admin password
        """
        data = self.valid_data.copy()
        data['admin'] = 'password'
        zdb = Zerodb('zdb', data=data)

        zdb.install()
        zdb._zerodb_sal.deploy.called_once_with()

        zdb.state.check('actions', 'install', 'ok')
        assert zdb.data['admin'] == 'password'
コード例 #22
0
    def test_start(self):
        """
        Test start action
        """
        zdb = Zerodb('zdb', data=self.valid_data)
        zdb.state.set('actions', 'install', 'ok')
        zdb.api.services.get = MagicMock()
        zdb._node_sal.freeports = MagicMock(return_value=[9900])
        zdb.start()

        zdb.api.services.get.assert_called_once_with(
            template_uid=CONTAINER_TEMPLATE_UID, name=zdb._container_name)
        zdb._zerodb_sal.start.assert_called_once_with()
        zdb.state.check('actions', 'start', 'ok')
コード例 #23
0
    def test_namespace_create(self):
        """
        Test namespace_set action
        """
        zdb = Zerodb('zdb', data=self.valid_data)
        zdb.state.set('actions', 'start', 'ok')
        zdb.api.services.get = MagicMock()
        zdb.namespace_create('namespace', 12, 'secret')

        zdb._zerodb_sal.create_namespace.assert_called_once_with('namespace')
        zdb._zerodb_sal.set_namespace_property.assert_has_calls([
            call('namespace', 'maxsize', 12),
            call('namespace', 'password', 'secret')
        ])
コード例 #24
0
    def test_install(self):
        """
        Test install action
        """
        zdb = Zerodb('zdb', data=self.valid_data)
        zdb.api.services.find_or_create = MagicMock()
        zdb._node_sal.freeports = MagicMock(return_value=[9900])

        zdb.install()

        zdb.api.services.find_or_create.assert_called_once_with(
            CONTAINER_TEMPLATE_UID,
            zdb._container_name,
            data=zdb._container_data)
        zdb.state.check('actions', 'install', 'ok')
コード例 #25
0
    def test_monitor_started(self):
        """
        Test _monitor action when zerodb should be started and it can be started
        """
        node = MagicMock()
        node.state.check.return_value = True

        zdb = Zerodb('zdb', data=self.valid_data)
        zdb.api.services.get = MagicMock(return_value=node)

        zdb._zerodb_sal.is_running = MagicMock(side_effect=[(False,), (True,)])
        zdb.state.set('actions', 'install', 'ok')
        zdb.state.set('actions', 'start', 'ok')
        zdb._monitor()
        zdb.state.check('status', 'running', 'ok')
コード例 #26
0
    def test_container_sal(self):
        zdb = Zerodb('zdb', data=self.valid_data)
        zdb._node_sal.containers.get = MagicMock(return_value='container')

        assert zdb._container_sal == 'container'
        zdb._node_sal.containers.get.assert_called_once_with(
            zdb._container_name)
コード例 #27
0
    def test_node_sal(self):
        """
        Test _node_sal property
        """
        get_node = patch('jumpscale.j.clients.zos.get', MagicMock(return_value='node_sal')).start()
        zdb = Zerodb('zdb', data=self.valid_data)

        assert zdb._node_sal == 'node_sal'
        get_node.assert_called_once_with(NODE_CLIENT)
コード例 #28
0
    def test_zerodb_sal(self):
        """
        Test node_sal property
        """
        zdb_sal = patch('js9.j.clients.zero_os.sal.get_zerodb',
                        MagicMock(return_value='zdb_sal')).start()
        zdb = Zerodb('zdb', data=self.valid_data)
        zdb.api.services.get = MagicMock()

        assert zdb._zerodb_sal == 'zdb_sal'
        assert zdb_sal.called
コード例 #29
0
    def test_zerodb_sal(self):
        """
        Test _zerodb_sal property
        """
        zdb = Zerodb('zdb', data=self.valid_data)
        self.valid_data['name'] = zdb.name
        zdb_sal = MagicMock()
        zdb._node_sal.primitives.from_dict.return_value = zdb_sal

        assert zdb._zerodb_sal == zdb_sal
        zdb._node_sal.primitives.from_dict.assert_called_once_with('zerodb', self.valid_data)
コード例 #30
0
 def test_namespace_delete(self):
     """
     Test namespace_delete action
     """
     zdb = Zerodb('zdb', data=self.valid_data)
     zdb.state.set('status', 'running', 'ok')
     zdb._namespace_exists_update_delete = MagicMock(return_value=True)
     zdb._deploy = MagicMock()
     zdb.namespace_delete('namespace')
     zdb._zerodb_sal.deploy.assert_called_once_with()