Example #1
0
def main():
    """
    Parse argument as command and execute that command with
    parameters containing the state of MySQL, ContainerPilot, etc.
    Default behavior is to run `pre_start` DB initialization.
    """
    if len(sys.argv) == 1:
        consul = Consul(envs={'CONSUL': os.environ.get('CONSUL', 'consul')})
        cmd = pre_start
    else:
        consul = Consul()
        try:
            cmd = globals()[sys.argv[1]]
        except KeyError:
            log.error('Invalid command: %s', sys.argv[1])
            sys.exit(1)

    my = MySQL()
    cp = ContainerPilot()
    cp.load()

    # what storage backend did we use?
    driver = os.environ.get('BACKUP_DRIVER', 'manta').lower()
    if driver == 'manta':
        storage = Manta()
    elif driver == 's3':
        storage = S3()
    elif driver == 'scp':
        storage = SCP()
    else:
        storage = None

    node = Node(mysql=my, consul=consul, storage=storage, cp=cp)

    cmd(node)
Example #2
0
def main():
    """
    Parse argument as command and execute that command with
    parameters containing the state of MySQL, ContainerPilot, etc.
    Default behavior is to run `pre_start` DB initialization.
    """
    if len(sys.argv) == 1:
        consul = Consul(envs={'CONSUL': os.environ.get('CONSUL', 'consul')})
        cmd = pre_start
    else:
        consul = Consul()
        try:
            cmd = globals()[sys.argv[1]]
        except KeyError:
            log.error('Invalid command: %s', sys.argv[1])
            sys.exit(1)

    storage_class = env('BACKUP_STORAGE_CLASS', 'manager.libmanta.Manta')

    my = MySQL()
    backup_store = get_class(storage_class)()
    cp = ContainerPilot()
    cp.load()
    node = Node(mysql=my, consul=consul, backup_store=backup_store, cp=cp)

    cmd(node)
Example #3
0
 def test_parse_with_consul_agent(self):
     self.environ['CONSUL_AGENT'] = '1'
     cp = ContainerPilot()
     cp.load(envs=self.environ)
     self.assertEqual(cp.config['consul'], 'localhost:8500')
     cmd = cp.config['coprocesses'][0]['command']
     host_cfg_idx = cmd.index('-retry-join') + 1
     self.assertEqual(cmd[host_cfg_idx], 'my.consul.example.com')
     self.assertEqual(cp.state, UNASSIGNED)
Example #4
0
 def test_parse_with_consul_agent(self):
     self.environ['CONSUL_AGENT'] = '1'
     cp = ContainerPilot()
     cp.load(envs=self.environ)
     self.assertEqual(cp.config['consul'], 'localhost:8500')
     cmd = cp.config['coprocesses'][0]['command']
     host_cfg_idx = cmd.index('-retry-join') + 1
     self.assertEqual(cmd[host_cfg_idx], 'my.consul.example.com:8500')
     self.assertEqual(cp.state, UNASSIGNED)
Example #5
0
 def setUp(self):
     logging.getLogger().setLevel(logging.WARN)
     consul = mock.MagicMock()
     manta = mock.MagicMock()
     my = mock.MagicMock()
     cp = ContainerPilot()
     cp.load(get_environ())
     my.datadir = tempfile.mkdtemp()
     cp.state = PRIMARY
     my.datadir = tempfile.mkdtemp()
     self.node = manage.Node(consul=consul, cp=cp, manta=manta, mysql=my)
Example #6
0
 def setUp(self):
     logging.getLogger().setLevel(logging.WARN)
     consul = mock.MagicMock()
     manta = mock.MagicMock()
     my = mock.MagicMock()
     cp = ContainerPilot()
     cp.load(get_environ())
     my.datadir = tempfile.mkdtemp()
     cp.state = PRIMARY
     my.datadir = tempfile.mkdtemp()
     self.node = manage.Node(consul=consul, cp=cp, manta=manta, mysql=my)
Example #7
0
 def setUp(self):
     logging.getLogger().setLevel(logging.WARN)
     consul = mock.MagicMock()
     my = mock.MagicMock()
     cp = ContainerPilot()
     cp.load(get_environ())
     temp_file = tempfile.NamedTemporaryFile()
     cp.path = temp_file.name
     my.datadir = tempfile.mkdtemp()
     self.node = manage.Node(consul=consul, cp=cp, mysql=my)
     self.node.ip = '192.168.1.101'
     self.node.name = 'node1'
Example #8
0
 def setUp(self):
     logging.getLogger().setLevel(logging.WARN)
     consul = mock.MagicMock()
     my = mock.MagicMock()
     cp = ContainerPilot()
     cp.load(get_environ())
     temp_file = tempfile.NamedTemporaryFile()
     cp.path = temp_file.name
     my.datadir = tempfile.mkdtemp()
     self.node = manage.Node(consul=consul, cp=cp, mysql=my)
     self.node.ip = '192.168.1.101'
     self.node.name = 'node1'
Example #9
0
    def test_parse_without_consul_agent(self):
        self.environ['CONSUL_AGENT'] = '0'
        cp = ContainerPilot()
        cp.load(envs=self.environ)
        self.assertEqual(cp.config['consul'], 'my.consul.example.com:8500')
        self.assertEqual(cp.config['coprocesses'], [])
        self.assertEqual(cp.state, UNASSIGNED)

        self.environ['CONSUL_AGENT'] = ''
        cp = ContainerPilot()
        cp.load(envs=self.environ)
        self.assertEqual(cp.config['consul'], 'my.consul.example.com:8500')
        self.assertEqual(cp.config['coprocesses'], [])
        self.assertEqual(cp.state, UNASSIGNED)
Example #10
0
    def test_update(self):
        self.environ['CONSUL_AGENT'] = '1'
        cp = ContainerPilot()
        cp.state = REPLICA
        cp.load(envs=self.environ)
        temp_file = tempfile.NamedTemporaryFile()
        cp.path = temp_file.name

        # no update expected
        cp.update()
        with open(temp_file.name, 'r') as updated:
            self.assertEqual(updated.read(), '')

        # force an update
        cp.state = PRIMARY
        cp.update()
        with open(temp_file.name, 'r') as updated:
            config = json.loads(updated.read())
            self.assertEqual(config['consul'], 'localhost:8500')
            cmd = config['coprocesses'][0]['command']
            host_cfg_idx = cmd.index('-retry-join') + 1
            self.assertEqual(cmd[host_cfg_idx], 'my.consul.example.com:8500')
def main():
    """
    Parse argument as command and execute that command with
    parameters containing the state of MySQL, ContainerPilot, etc.
    Default behavior is to run `pre_start` DB initialization.
    """
    if len(sys.argv) == 1:
        consul = Consul(envs={'CONSUL': os.environ.get('CONSUL', 'consul')})
        cmd = pre_start
    else:
        consul = Consul()
        try:
            cmd = globals()[sys.argv[1]]
        except KeyError:
            log.error('Invalid command: %s', sys.argv[1])
            sys.exit(1)

    cp = ContainerPilot()
    cass = CassandraService()
    cp.load()
    print(consul)
    node = Node(kvstore=consul, cp=cp, service=cass)

    cmd(node)
Example #12
0
def main():
    """
    Parse argument as command and execute that command with
    parameters containing the state of MySQL, ContainerPilot, etc.
    Default behavior is to run `pre_start` DB initialization.
    """
    if len(sys.argv) == 1:
        consul = Consul(envs={'CONSUL': os.environ.get('CONSUL', 'consul')})
        cmd = pre_start
    else:
        consul = Consul()
        try:
            cmd = globals()[sys.argv[1]]
        except KeyError:
            log.error('Invalid command: %s', sys.argv[1])
            sys.exit(1)

    my = MySQL()
    manta = Manta()
    cp = ContainerPilot()
    cp.load()
    node = Node(mysql=my, consul=consul, manta=manta, cp=cp)

    cmd(node)
Example #13
0
def main():
    """
    Parse argument as command and execute that command with
    parameters containing the state of MySQL, ContainerPilot, etc.
    Default behavior is to run `pre_start` DB initialization.
    """
    if len(sys.argv) == 1:
        consul = Consul(envs={'CONSUL': os.environ.get('CONSUL', 'consul')})
        cmd = pre_start
    else:
        consul = Consul()
        try:
            cmd = globals()[sys.argv[1]]
        except KeyError:
            log.error('Invalid command: %s', sys.argv[1])
            sys.exit(1)

    my = MySQL()
    manta = Manta()
    cp = ContainerPilot()
    cp.load()
    node = Node(mysql=my, consul=consul, manta=manta, cp=cp)

    cmd(node)
Example #14
0
    def test_parse_without_consul_agent(self):
        self.environ['CONSUL_AGENT'] = '0'
        cp = ContainerPilot()
        cp.load(envs=self.environ)
        self.assertEqual(cp.config['consul'], 'my.consul.example.com:8500')
        self.assertEqual(cp.config['coprocesses'], [])
        self.assertEqual(cp.state, UNASSIGNED)

        self.environ['CONSUL_AGENT'] = ''
        cp = ContainerPilot()
        cp.load(envs=self.environ)
        self.assertEqual(cp.config['consul'], 'my.consul.example.com:8500')
        self.assertEqual(cp.config['coprocesses'], [])
        self.assertEqual(cp.state, UNASSIGNED)
Example #15
0
    def test_update(self):
        self.environ['CONSUL_AGENT'] = '1'
        cp = ContainerPilot()
        cp.state = REPLICA
        cp.load(envs=self.environ)
        temp_file = tempfile.NamedTemporaryFile()
        cp.path = temp_file.name

        # no update expected
        cp.update()
        with open(temp_file.name, 'r') as updated:
            self.assertEqual(updated.read(), '')

        # force an update
        cp.state = PRIMARY
        cp.update()
        with open(temp_file.name, 'r') as updated:
            config = json.loads(updated.read())
            self.assertEqual(config['consul'], 'localhost:8500')
            cmd = config['coprocesses'][0]['command']
            host_cfg_idx = cmd.index('-retry-join') + 1
            self.assertEqual(cmd[host_cfg_idx], 'my.consul.example.com')