Пример #1
0
def model_init(**kwargs):
    """Set this host to be the Geppetto master and save global config"""
    for name, value in kwargs.iteritems():
        if value:
            ConfigClassParameter.set_config_parameter(name.upper(), value)
    master_hostname = network.get_hostname()
    Master.promote_node(master_hostname)
    master = get_or_create_node(master_hostname)
    Override.\
        update_or_create_override(master,
                                  ConfigClassParameter.get_by_name(
                                  ConfigClassParameter.VPX_LABEL_PREFIX),
                                  'Citrix OpenStack VPX')

    geppetto_roles = [
        Role.get_by_name(Role.CELERY_WORKER),
        Role.get_by_name(Role.CELERY_CAMERA)
    ]
    if kwargs['vpx_master_db_host'] in [master_hostname, 'localhost']:
        geppetto_roles.append(Role.get_by_name(Role.MYSQL))
    if kwargs['vpx_master_queue_host'] in [master_hostname, 'localhost']:
        geppetto_roles.append(Role.get_by_name(Role.RABBITMQ))
    roles_to_apply = [r for r in geppetto_roles \
                                if not NodeRoleAssignment.exists(master, r)]
    NodeRoleAssignment.add_roles_to_node(master, roles_to_apply, True)
Пример #2
0
def update_related_config_params(roles, node_fqdn):
    """Update all config values affected by the given worker type moving
    to a new node. Then restart all affected services.
    """
    affected_config_parms = []
    for role in roles:
        if role.description:
            affected_config_parms.extend(RoleDesConfigParamAssignment.\
                            get_param_labels_by_description(role.description))
    affected_config_parms = set(affected_config_parms)

    for param_label in affected_config_parms:
        ConfigClassParameter.set_config_parameter(param_label, node_fqdn)
        Override.update_overrides(ConfigClassParameter.\
                                                get_by_name(param_label))
        GroupOverride.update_overrides(ConfigClassParameter.\
                                                get_by_name(param_label))

    # restart appropriate services on the affected nodes or
    # track nodes whose CLI configuration require a refresh
    node_dict = {}
    details = ConfigClassParameter.\
                            get_details_for_params(affected_config_parms)
    for param_label in affected_config_parms:
        applies_to = details[param_label]['applies-to']
        for role_name in applies_to:
            role_name = str(role_name)
            affected_nodes = Node.get_fqdns_by_role(role_name)
            for n in affected_nodes:
                if n in node_dict and role_name not in node_dict[n]:
                    node_dict[n].append(role_name)
                elif n != node_fqdn:
                    node_dict[n] = [role_name]
            affected_nodes = Node.get_fqdns_by_role(role_name,
                                                    is_service=False)
            for n in affected_nodes:
                if n not in node_dict:
                    node_dict[n] = []

    svc_restart = ConfigClassParameter.\
                get_by_name(ConfigClassParameter.VPX_RESTART_SERVICES)
    for node_fqdn, role_to_restart in node_dict.iteritems():
        if len(role_to_restart) > 0:
            Override.update_or_create_override(Node.get_by_name(node_fqdn),
                                               svc_restart, role_to_restart,
                                               True)

    return node_dict.keys()
Пример #3
0
    def test_Compute___add_database_valid_params_returns_task_id(self):
        self._add_dummy_node('test1')

        result = self.svc.Compute___add_database("test1",
                                                 {"MYSQL_PASS": "******"})
        self.assertEqual(result, "task_id")

        dummy_node = self._get_dummy_node()
        role_list = dummy_node.get_roles()
        self.assertEqual([Role.get_by_name("mysqld")], role_list)

        mysql_pass = ConfigClassParameter.get_by_name("MYSQL_PASS")
        self.assertEqual("password", mysql_pass.default_value)

        mysql_host = ConfigClassParameter.get_by_name("MYSQL_HOST")
        self.assertEqual("test1", mysql_host.default_value)
Пример #4
0
def assign_and_configure_roles_to_node(node_fqdn, role_list, node_config=None):
    node = Node.get_by_name(node_fqdn)
    if node_config != None:
        for param_label, value in node_config.iteritems():
            param = ConfigClassParameter.get_by_name(param_label)
            Override.update_or_create_override(node, param, value)
    roles = [Role.get_by_name(role_name) for role_name in role_list]
    NodeRoleAssignment.add_roles_to_node(node, roles, True)
Пример #5
0
 def test_copy_node_overrides(self):
     node_src = self._add_dummy_node('node_src')
     node_dst = self._add_dummy_node('node_dst')
     c1 = config.get_by_name('HAPI_PASS')
     c2 = config.get_by_name('HAPI_USER')
     overrides = \
         [Override.\
          objects.create(node=node_src,
                         config_class_parameter=c1,
                         value='mysecret'),
          Override.\
          objects.create(node=node_src,
                         config_class_parameter=c2,
                         value='myuser'), ]
     Override.copy_node_overrides(node_dst, overrides)
     self.assertDictEqual(node_dst.get_overrides_dict(),
                      node_src.get_overrides_dict())
Пример #6
0
 def _add_dummy_override(self,
                         fqdn='test_fqdn',
                         config="VPX_DESCRIPTION",
                         value="test"):
     self._add_dummy_node(fqdn)
     node = self._get_dummy_node()
     config_class_parameter = ConfigClassParameter.get_by_name(config)
     Override.objects.create(node=node,
                             config_class_parameter=config_class_parameter,
                             value=value)
Пример #7
0
    def test_Compute___add_message_queue_valid_params_returns_task_id(self):
        self._add_dummy_node('test1')

        result = self.svc.Compute___add_message_queue("test1")
        self.assertEqual(result, "task_id")

        dummy_node = self._get_dummy_node()
        role_list = dummy_node.get_roles()
        self.assertEqual([Role.get_by_name("rabbitmq-server")], role_list)

        rabbit_host = ConfigClassParameter.get_by_name("RABBIT_HOST")
        self.assertEqual("test1", rabbit_host.default_value)
Пример #8
0
 def test_get_overrides(self):
     node = self._add_blank_node()
     d1 = {config.HAPI_USER: '******',
           config.HAPI_PASS: '******',
           config.MYSQL_USER: '******',
           config.MYSQL_PASS: '******', }
     for key, value in d1.iteritems():
         Override.update_or_create_override(node,
                                            config.get_by_name(key),
                                            value)
     d2 = node.get_overrides_dict()
     self.assertDictEqual(d1, d2)
Пример #9
0
def model_reset():
    """Recover the database to a pristine state"""
    Node.objects.all().delete()
    master = Master.get_infrastructure_master()
    master.fqdn = 'master'
    master.promoted_date = datetime.datetime(2001, 1, 1, 0, 0, 0, 0)
    master.save()
    root = User.objects.get(username='******')
    root.last_login = datetime.datetime(2001, 1, 1, 0, 0, 0, 0)
    root.save()
    config = ConfigClassParameter.get_by_name(ConfigClassParameter.\
                                              VPX_LOGGING_COLLECTOR)
    config.default_value = 'localhost'
    config.save()
Пример #10
0
    def test_BlockStorage___add_workers_valid_parms_returns_task_id(self):
        self._add_dummy_node('test1')

        result = self.svc.BlockStorage___add_workers(["test1"], {
            "TYPE": "iscsi",
            "VOLUME_DISK_SIZE_GB": "5"
        })
        self.assertEqual(result, "task_id")

        dummy_node = self._get_dummy_node()
        role_list = dummy_node.get_roles()
        self.assertEqual([Role.get_by_name("openstack-nova-volume")],
                         role_list)

        volume_driver = ConfigClassParameter.get_by_name("VOLUME_DRIVER")
        self.assertEqual("nova.volume.driver.ISCSIDriver",
                         volume_driver.default_value)

        use_local_volumes = ConfigClassParameter.\
                                get_by_name("USE_LOCAL_VOLUMES")
        self.assertEqual("True", use_local_volumes.default_value)

        size = ConfigClassParameter.get_by_name("VOLUME_DISK_SIZE_GB")
        self.assertEqual("5", size.default_value)
Пример #11
0
def get_or_create_node(node_fqdn):
    try:
        node = Node.get_by_name(node_fqdn)
    except:
        node = Node.create(node_fqdn)
        # Generate and assign a Host GUID
        host_guid = _generate_host_guid()
        param = ConfigClassParameter.get_by_name(
            ConfigClassParameter.HOST_GUID)
        Override.update_or_create_override(node, param, host_guid)
        # Assign default roles on node creation
        default_roles = Role.get_default_roles()
        NodeRoleAssignment.add_roles_to_node(node, default_roles)
        # determine if we can add celeryd on each worker. This is
        # possible only if the DB backend is != sqlite3
        if DATABASES['default']['ENGINE'] == 'django.db.backends.mysql':
            celery_role = Role.get_by_name(Role.CELERY_WORKER)
            NodeRoleAssignment.add_roles_to_node(node, [celery_role], True)
    return node
Пример #12
0
    def test_BlockStorage___add_workers_valid_parms_returns_task_id_sm(self):
        self._add_dummy_node('test1')

        result = self.svc.BlockStorage___add_workers(["test1"],
                                                     {"TYPE": "xenserver_sm"})
        self.assertEqual(result, "task_id")

        dummy_node = self._get_dummy_node()
        role_list = dummy_node.get_roles()
        self.assertEqual([Role.get_by_name("openstack-nova-volume")],
                         role_list)

        volume_driver = ConfigClassParameter.get_by_name("VOLUME_DRIVER")
        self.assertEqual("nova.volume.xensm.XenSMDriver",
                         volume_driver.default_value)

        use_local_volumes = ConfigClassParameter.\
                                get_by_name("USE_LOCAL_VOLUMES")
        self.assertEqual("False", use_local_volumes.default_value)
Пример #13
0
def create_swift_rings(hostnames):
    """This attempts to create the swift ring file on the master,
    given the specified hostnames of the swift object nodes."""
    # Resolve IPs
    # TODO - we should have this info in the facts
    ips = []
    for hostname in hostnames:
        ips.append(socket.gethostbyname(hostname))
    ips_str = string.join(ips, " ")

    # Assign Ring Builder Role: runs on this host
    node_fqdn = network.get_hostname()
    node = Node.get_by_name(node_fqdn)

    Override.update_or_create_override(
        node,
        ConfigClassParameter.get_by_name(ConfigClassParameter.SWIFT_NODES_IPS),
        ips_str)
    NodeRoleAssignment.add_roles_to_node(node,
                                         [Role.get_by_name(Role.RING_BUILDER)],
                                         True)
    return node_fqdn
Пример #14
0
    def _add_dummy_node(self, fqdn='test_fqdn', is_enabled=True):
        self.dummy_node_fqdn = fqdn
        node = Node.create(fqdn)
        node.enabled = is_enabled
        import pickle
        node.facts = pickle.dumps({
            "geppetto_status_running_services":
            "openstack-nova-api,openstack-nova-compute",
            "geppetto_status_stopped_services": "openstack-nova-network",
            "host_fqdn": "test_host",
            "ipaddress_eth0": "169.254.0.2",
            "ipaddress_eth1": "127.0.0.1",
            "interfaces": "'eth0,eth1,eth2,lo'",
        })
        node.save()
        node.joined_date = datetime.datetime(2001, 1, 1, 0, 0, 0, 0)

        # make the host guid predictable
        param = ConfigClassParameter.get_by_name(
            ConfigClassParameter.HOST_GUID)
        Override.update_or_create_override(node, param, "00:00:00:00:00:00")

        return node
Пример #15
0
 def test_config_get_all(self):
     configs = config.get_values()
     self.assertGreater(len(configs), 0, '')
Пример #16
0
 def _test_method_assert_equal(testrunner, name, value):
     config.set_config_parameter(name, value)
     self.assertEqual(value, config.get_value_by_name(name))