def test_opscenter_connect():

    opscenter = OpsCenter(settings.OPSCENTER_HOSTNAME,
                          settings.OPSCENTER_USERNAME,
                          settings.OPSCENTER_PASSWORD)
    assert opscenter.connect(timeout=settings.OPSCENTER_CONNECTION_TIMEOUT,
                             attempts=settings.OPSCENTER_RETRY_ATTEMPTS)
Esempio n. 2
0
def test_install_datacenter():

    NODE_NAME = 'datanode-01c'

    opscenter = OpsCenter(settings.OPSCENTER_HOSTNAME, settings.OPSCENTER_USERNAME, settings.OPSCENTER_PASSWORD)
    assert opscenter.connect(timeout=settings.OPSCENTER_CONNECTION_TIMEOUT, attempts=settings.OPSCENTER_RETRY_ATTEMPTS)
    
    clusters = Cluster(opscenter.url, opscenter.session)
    created_cluster = clusters.add(**{
        'name': 'cluster-c'
    })

    datacenters = DataCenter(opscenter.url, opscenter.session)
    created_datacenter = datacenters.add(**{
        'name': 'datacenter-cluster-c', 
        'cluster-id': created_cluster['id'],
    })

    nodes = Node(opscenter.url, opscenter.session)
    created_node = nodes.add(**{ 
        'name': NODE_NAME, 
        'datacenter-id': created_datacenter['id'],
        'ssh-management-address': socket.gethostbyname(NODE_NAME),
        'seed': True,
        'rack': 'rack-01',
    })

    assert created_node is not None
    assert created_node.get('id') is not None
    
    actions = InstallActions(opscenter.url, opscenter.session)
    datacenter_install_action = actions.install_datacenter(datacenter_id=created_datacenter['id'])
    assert datacenter_install_action is not None
Esempio n. 3
0
def test_datacenter_add():

    CLUSTER_NAME = 'test-cassandra-cluster-with-datacenter'

    opscenter = OpsCenter(settings.OPSCENTER_HOSTNAME,
                          settings.OPSCENTER_USERNAME,
                          settings.OPSCENTER_PASSWORD)
    assert opscenter.connect(timeout=settings.OPSCENTER_CONNECTION_TIMEOUT,
                             attempts=settings.OPSCENTER_RETRY_ATTEMPTS)

    clusters = Cluster(opscenter.url, opscenter.session)
    datacenters = DataCenter(opscenter.url, opscenter.session)

    created_cluster = clusters.add(**{'name': CLUSTER_NAME})
    assert created_cluster is not None
    assert created_cluster.get('datacenter') == []

    created_datacenter = datacenters.add(
        **{
            'name': 'test-cassandra-cluster-datacenter',
            'cluster-id': created_cluster.get('id')
        })
    assert created_datacenter is not None

    for cluster in clusters.filter(by_name=CLUSTER_NAME):
        for dc in cluster.get('datacenter'):
            assert dc['id'] == created_datacenter['id']
Esempio n. 4
0
def test_datacenter_init():

    opscenter = OpsCenter(settings.OPSCENTER_HOSTNAME,
                          settings.OPSCENTER_USERNAME,
                          settings.OPSCENTER_PASSWORD)
    assert opscenter.connect(timeout=settings.OPSCENTER_CONNECTION_TIMEOUT,
                             attempts=settings.OPSCENTER_RETRY_ATTEMPTS)
    assert DataCenter(opscenter.url, opscenter.session)
Esempio n. 5
0
    def connect(self):
        ''' connect to OpsCenter
        '''
        self.opscenter = OpsCenter(
            hostname    = self._deployments.get('opscenter', {}).get('hostname'),
            username    = self._deployments.get('opscenter', {}).get('username'),
            password    = self._deployments.get('opscenter', {}).get('password')
        )
        if self.opscenter.connect(
            timeout     = self._deployments.get('opscenter', {}).get('timeout'), 
            attempts    = self._deployments.get('opscenter', {}).get('attempts')):
        
            return True

        return False    
Esempio n. 6
0
def test_cluster_add():

    CLUSTER_NAME = 'test-cassandra-cluster'

    opscenter = OpsCenter(settings.OPSCENTER_HOSTNAME, settings.OPSCENTER_USERNAME, settings.OPSCENTER_PASSWORD)
    assert opscenter.connect(timeout=settings.OPSCENTER_CONNECTION_TIMEOUT, attempts=settings.OPSCENTER_RETRY_ATTEMPTS)
    
    clusters = Cluster(opscenter.url, opscenter.session)
    created_cluster = clusters.add(**{ 'name': CLUSTER_NAME, })

    assert created_cluster is not None
    assert created_cluster.get('id') is not None
    assert created_cluster.get('datacenter') == []
    
    clusters_list = clusters.filter(by_name=CLUSTER_NAME)
    assert len(clusters_list) > 0
Esempio n. 7
0
def test_config_profile_add():

    opscenter = OpsCenter(settings.OPSCENTER_HOSTNAME,
                          settings.OPSCENTER_USERNAME,
                          settings.OPSCENTER_PASSWORD)
    assert opscenter.connect(timeout=settings.OPSCENTER_CONNECTION_TIMEOUT,
                             attempts=settings.OPSCENTER_RETRY_ATTEMPTS)

    config_profiles = ConfigProfile(opscenter.url, opscenter.session)

    kwargs = {
        'name': 'test-default-profile-v673',
        'datastax-version': '6.7.3',
        'comment': 'Test config profile for DSE 6.7.3 with default parameters',
        'json': {
            'cassandra-yaml': {
                "authenticator":
                "com.datastax.bdp.cassandra.auth.DseAuthenticator",
                "num_tokens": 8,
                "allocate_tokens_for_local_replication_factor": 2,
                "endpoint_snitch":
                "org.apache.cassandra.locator.GossipingPropertyFileSnitch",
                "compaction_throughput_mb_per_sec": 64
            },
            "dse-yaml": {
                "authorization_options": {
                    "enabled": True
                },
                "authentication_options": {
                    "enabled": True
                },
                "dsefs_options": {
                    "enabled": True
                }
            }
        },
    }
    created_config_profile = config_profiles.add(**kwargs)
    assert created_config_profile is not None

    config_profiles_list = config_profiles.get()
    assert config_profiles_list.get('count', 0) > 0
Esempio n. 8
0
def test_repository_add():

    opscenter = OpsCenter(settings.OPSCENTER_HOSTNAME,
                          settings.OPSCENTER_USERNAME,
                          settings.OPSCENTER_PASSWORD)
    assert opscenter.connect(timeout=settings.OPSCENTER_CONNECTION_TIMEOUT,
                             attempts=settings.OPSCENTER_RETRY_ATTEMPTS)

    repositories = Repository(opscenter.url, opscenter.session)

    kwargs = {
        "name": "test-repository",
        "username": "******",
        "password": "******",
        "comment": "Test DataStax Repository",
    }
    created_repo = repositories.add(**kwargs)
    assert created_repo is not None

    repos_list = repositories.get()
    assert repos_list.get('count', 0) > 0
def test_credentials_add():

    opscenter = OpsCenter(settings.OPSCENTER_HOSTNAME,
                          settings.OPSCENTER_USERNAME,
                          settings.OPSCENTER_PASSWORD)
    assert opscenter.connect(timeout=settings.OPSCENTER_CONNECTION_TIMEOUT,
                             attempts=settings.OPSCENTER_RETRY_ATTEMPTS)

    creds = Credentials(opscenter.url, opscenter.session)

    kwargs = {
        "name": "test-ssh-creds",
        "become-mode": "sudo",
        "use-ssh-keys": True,
        "login-user": "******",
        "ssh-private-key": "test/resources/keys/cassandra",
    }
    created_creds = creds.add(**kwargs)
    assert created_creds is not None

    creds_list = creds.get()
    assert creds_list.get('count', 0) > 0
Esempio n. 10
0
class Topology():

    def __init__(self, deployments):
        
        self._deployments = deployments
        self.opscenter      = None

    def deploy(self):
        ''' deploy
        '''
        if not self.connect():
            logger.error('Cannot connect to OpsCenters')
            return
        
        self.deploy_credentials()
        self.deploy_config_profiles()
        self.deploy_repositories()
        self.deploy_clusters()

    def dump(self, sections, output_path):
        ''' dump sections
        '''
        if not self.connect():
            logger.error('Cannot connect to OpsCenters')
            return

        with open(output_path, 'w') as output:
            if 'credentials' in sections:
                self.dump_credentials(output)
            
            if 'config-profiles' in sections:
                self.dump_config_profiles(output)

            if 'repositories' in sections:
                self.dump_repositories(output)

            if 'datacenters' in sections:
                self.dump_datacenters(output)

            if 'clusters' in sections:
                self.dump_clusters(output)

    def connect(self):
        ''' connect to OpsCenter
        '''
        self.opscenter = OpsCenter(
            hostname    = self._deployments.get('opscenter', {}).get('hostname'),
            username    = self._deployments.get('opscenter', {}).get('username'),
            password    = self._deployments.get('opscenter', {}).get('password')
        )
        if self.opscenter.connect(
            timeout     = self._deployments.get('opscenter', {}).get('timeout'), 
            attempts    = self._deployments.get('opscenter', {}).get('attempts')):
        
            return True

        return False    

    def deploy_credentials(self):
        ''' deploy credentials
        '''
        credentials = Credentials(self.opscenter.url, self.opscenter.session)
        for creds in self._deployments.get('credentials', []):
            created_creds = credentials.add(**creds)
            if created_creds:
                logger.info(created_creds)

    def dump_credentials(self, output):
        ''' dump credentials
        '''
        credentials = Credentials(self.opscenter.url, self.opscenter.session)
        json_dump(output, {'credentials': credentials.get().get('results', []) })

    def deploy_config_profiles(self):
        ''' deploy config profiles
        '''
        config_profiles = ConfigProfile(self.opscenter.url, self.opscenter.session)
        for conf_profile in self._deployments.get('config-profiles', []):
            created_conf_profile = config_profiles.add(**conf_profile)
            if created_conf_profile:
                logger.info(created_conf_profile)

    def dump_config_profiles(self, output):
        ''' dump config profiles
        '''
        config_profiles = ConfigProfile(self.opscenter.url, self.opscenter.session)
        json_dump(output, {'config-profiles': config_profiles.get().get('results', []) })

    def deploy_repositories(self):
        ''' deploy repositories
        '''
        repositories = Repository(self.opscenter.url, self.opscenter.session)
        for repo in self._deployments.get('repositories', []):
            created_repo = repositories.add(**repo)
            if created_repo:
                logger.info(created_repo)

    def dump_repositories(self, output):
        ''' dump repositories
        '''
        repositories = Repository(self.opscenter.url, self.opscenter.session)
        json_dump(output, {'repositories': repositories.get().get('results', []) })

    def deploy_clusters(self):
        ''' deploy clusters
        '''
        clusters            = Cluster(self.opscenter.url, self.opscenter.session)
        config_profiles     = ConfigProfile(self.opscenter.url, self.opscenter.session)
        repositories        = Repository(self.opscenter.url, self.opscenter.session)
        datacenters         = DataCenter(self.opscenter.url, self.opscenter.session)
        nodes               = Node(self.opscenter.url, self.opscenter.session)

        for cluster in self._deployments.get('clusters', []):

            cluster_nodes = cluster.pop('nodes', [])
            datacenter = cluster.pop('datacenter')
            
            config = get_resource_by_name( cluster.get('config-profile-id', None), config_profiles)
            cluster['config-profile-id'] = config.get('id', 'Unknown')

            repo = get_resource_by_name( cluster.get('repository-id', None), repositories)
            cluster['repository-id'] = repo.get('id', 'Unknown')

            created_cluster = clusters.add(**cluster)
            if not created_cluster:
                created_cluster = get_resource_by_name(cluster.get('name'), clusters)
                if not created_cluster:
                    logger.error('Cannot create cluster, {}'.format(cluster))
                    continue

            created_datacenter = datacenters.add(**{ 'name': datacenter, 'cluster-id': created_cluster['id'] })
            if not created_datacenter:
                created_datacenter = get_resource_by_name(datacenter, datacenters)
                if not created_datacenter:
                    logger.error('Cannot create datacenter, name: {}, cluster: {}'.format(datacenter, created_cluster))
                    continue

            for node in cluster_nodes:
                node['datacenter-id'] = created_datacenter['id']
                created_node = nodes.add(**node)
                if not created_node:
                    created_node = get_resource_by_name(node['name'], nodes)
                    if not created_node:
                        logger.error('Cannot create node, {}'.format(node))
                        continue
def test_opscenter_init():

    assert OpsCenter(settings.OPSCENTER_HOSTNAME, settings.OPSCENTER_USERNAME,
                     settings.OPSCENTER_PASSWORD)