コード例 #1
0
 def test_uninstall_with_value_error(self):
     bc = Faucet('f', data=self.valid_data)
     bc.api = MagicMock()
     sp = MagicMock()
     fs = MagicMock()
     fs.path = 'mypath'
     fs.side_effect = ValueError()
     sp.get.return_value = fs
     bc._node_sal.storagepools.get = MagicMock(return_value=sp)
     bc.state.set("actions", "install", "ok")
     bc.uninstall()
     assert fs.delete.called
     with pytest.raises(StateCheckError):
         bc.state.check('status', 'running', 'ok')
         bc.state.check('actions', 'intsall', 'ok')
コード例 #2
0
    def test_node_sal(self):

        get_node = patch('jumpscale.j.clients.zos.get',
                         MagicMock(return_value='node')).start()
        bc = Faucet('f', data=self.valid_data)
        node_sal = bc._node_sal
        assert get_node.called
        assert node_sal == 'node'
コード例 #3
0
    def test_stop(self):
        bc = Faucet('f', data=self.valid_data)
        bc.state.set('actions', 'start', 'ok')
        bc.state.set('status', 'running', 'ok')

        bc.api = MagicMock()
        bc._container_sal.stop = MagicMock()
        bc._block_creator.schedule_action = MagicMock()

        bc.stop()

        bc._container_sal.stop.assert_called_once()
        bc._block_creator.schedule_action.assert_called_once_with("stop")

        with pytest.raises(StateCheckError):
            bc.state.check('status', 'running', 'ok')
            bc.state.check('actions', 'start', 'ok')
コード例 #4
0
    def test_uninstall(self):
        bc = Faucet('f', data=self.valid_data)
        sp = MagicMock()
        fs = MagicMock()
        fs.path = 'mypath'
        sp.get.return_value = fs
        bc.api = MagicMock()
        bc._node_sal.storagepools.get = MagicMock(return_value=sp)
        bc._block_creator.schedule_action = MagicMock()
        bc.state.set("actions", "install", "ok")
        bc.uninstall()
        fs.delete.assert_called_once()

        bc._block_creator.schedule_action.assert_called_once()

        with pytest.raises(StateCheckError):
            bc.state.check('status', 'running', 'ok')
            bc.state.check('actions', 'intsall', 'ok')
コード例 #5
0
    def test_start_not_install(self):
        bc = Faucet('f', data=self.valid_data)
        bc._get_container = MagicMock()
        bc.api = MagicMock()
        bc._block_creator.schedule_action = MagicMock()
        bc._write_caddyfile = MagicMock()

        with pytest.raises(StateCheckError):
            bc.start()
コード例 #6
0
    def test_install(self):
        bc = Faucet('f', data=self.valid_data)
        # sp = MagicMock()
        # fs = MagicMock()
        # fs.path = 'mypath'
        # sp.get.return_value = fs
        # bc._node_sal.storagepools.get = MagicMock(return_value=sp)
        bc.api = MagicMock()

        waitf = MagicMock()
        bc._block_creator.schedule_action = MagicMock(return_value=waitf)

        bc.install()

        assert bc.api.services.find_or_create.called
        bc._block_creator.schedule_action.assert_called_once_with("install")
        # FIXME CHECK FOR WAITF
        # assert waitf.called

        bc.state.check('actions', 'install', 'ok')
コード例 #7
0
 def test_upgrade(self):
     bc = Faucet('f', data=self.valid_data)
     bc.stop = MagicMock()
     bc.start = MagicMock()
     bc.upgrade("myflist")
     bc.stop.assert_called_once()
     bc.start.assert_called_once()
     assert bc.data['faucetFlist'] == 'myflist'
コード例 #8
0
    def test_start(self):
        bc = Faucet('f', data=self.valid_data)
        bc.state.set('actions', 'install', 'ok')
        bc._get_container = MagicMock()
        bc.api = MagicMock()
        bc._block_creator.schedule_action = MagicMock()
        bc.write_caddyfile = MagicMock()

        bc.start()

        bc._get_container.assert_called_once()
        assert bc.write_caddyfile.called

        bc.state.check('status', 'running', 'ok')
        bc.state.check('actions', 'start', 'ok')
コード例 #9
0
    def test_install_with_value_error(self):
        bc = Faucet('f', data=self.valid_data)

        bc.api = MagicMock()

        bc._create_blockcreator = MagicMock(side_effect=RuntimeError())
        bc._block_creator.schedule_action = MagicMock()

        # TODO: better execption catching.
        with pytest.raises(Exception):
            bc.install()
            bc.state.check('actions', 'install', 'ok')
コード例 #10
0
    def test__get_container_not_installed(self):
        bc = Faucet('f', data=self.valid_data)
        sp = MagicMock()
        fs = MagicMock()
        fs.path = 'mypath'
        sp.get.return_value = fs
        bc._node_sal.storagepools.get = MagicMock(return_value=sp)
        bc.api = MagicMock()
        bc._node_sal.client.filesystem = MagicMock()

        bc._get_caddyfile = MagicMock()
        bc._write_caddyfile = MagicMock()

        with pytest.raises(StateCheckError):
            bc._get_container()

            bc._node_sal.client.filesystem.mkdir.assert_has_calls(
                [mock.call('mypath/wallet'),
                 mock.call('mypath/caddy-certs')])

            assert bc._node_sal.containers.create.called
            assert bc._get_caddyfile.called
コード例 #11
0
 def test_blockcreator_service_name(self):
     bc = Faucet('f', data=self.valid_data)
     assert bc._block_creator_name == "block_creator-{}".format(bc.guid)
コード例 #12
0
 def test_service_container_name(self):
     bc = Faucet('f', data=self.valid_data)
     assert bc._container_name == "container-{}".format(bc.guid)
コード例 #13
0
 def test_create_valid_data(self):
     bc = Faucet(name='f', data=self.valid_data)
     assert bc.data == self.valid_data
コード例 #14
0
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
logger = logging.getLogger(__name__)

LISTENING_CHANNELS = ["faucet"]
FAUCET_APPROVE_ROLE = "faucet-approvers"
MOD_ROLE = "mod"
CODA_FAUCET_AMOUNT = os.environ.get("FAUCET_AMOUNT")
# A Dictionary to keep track of users
# who have requested faucet funds
ACTIVE_REQUESTS = {}
DISCORD_API_KEY = os.environ.get("DISCORD_API_KEY")
METRICS_PORT = int(os.environ.get("FAUCET_METRICS_PORT"))

executor = concurrent.futures.ThreadPoolExecutor(max_workers=5)
client = discord.Client()
faucet = Faucet()

SENT_TRANSACTION_THIS_BLOCK = False

# PROMETHEUS METRICS
TRANSACTION_COUNT = prometheus_client.Counter(
    "faucet_transactions_sent",
    "Number of Transactions sent since the process started")
TOTAL_CODA_SENT = prometheus_client.Counter(
    "faucet_coda_sent", "Amount of Coda sent since the process started")
PROCESS_METRICS = prometheus_client.ProcessCollector(namespace='faucet')
PLEASE_WAIT_ERRORS = prometheus_client.Counter(
    "faucet_please_wait_errors",
    "Number of 'Please Wait' Errors that have been issued")
BLOCK_NOTIFICATIONS_RECIEVED = prometheus_client.Counter(
    "faucet_block_notifications_recieved",