Пример #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 test_copy_role_assignements(self):
     node_src = self._add_dummy_node('node_src')
     node_dst = self._add_dummy_node('node_dst')
     role_assignments = \
           [NodeRoleAssignment.\
            objects.create(node=node_src,
                           role=Role.get_by_name('openstack-nova-compute'),
                           enabled=True),
            NodeRoleAssignment.\
            objects.create(node=node_src,
                           role=Role.get_by_name('openstack-nova-api'),
                           enabled=True), ]
     NodeRoleAssignment.copy_role_assignments_to_node(role_assignments,
                                                      node_dst)
     self.assertListEqual(node_src.get_roles(), node_dst.get_roles())
Пример #3
0
    def test_Network___add_workers__valid_vlan_parms_returns_task_id(self):
        self._add_dummy_node('test1')

        result = self.svc.Network___add_workers(
            ["test1"], {
                "MODE": "vlan",
                "GUEST_NETWORK_BRIDGE": "xenbr1",
                "GUEST_NW_VIF_MODE": "static",
                "GUEST_NW_VIF_IP": "192.168.0.200",
                "GUEST_NW_VIF_NETMASK": "255.255.255.0"
            })
        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-network")],
                         role_list)

        network_manager = ConfigClassParameter.\
                                get_by_name("NETWORK_MANAGER")
        self.assertEqual("nova.network.manager.VlanManager",
                         network_manager.default_value)
        # TODO stub out hpai layer to test other one

        overrides = dummy_node.get_overrides_dict()
        self.assertEqual("static", overrides["GUEST_NW_VIF_MODE"])
        self.assertEqual("192.168.0.200", overrides["GUEST_NW_VIF_IP"])
        self.assertEqual("255.255.255.0", overrides["GUEST_NW_VIF_NETMASK"])
Пример #4
0
    def test_Compute__add_apis_valid_parms_returns_task_id(self):
        self._add_dummy_node('test1')

        result = self.svc.Compute___add_apis(["test1"], {})
        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-api"),
            Role.get_by_name("openstack-dashboard")
        ], role_list)

        host = ConfigClassParameter.\
                                get_by_name("COMPUTE_API_HOST")
        self.assertEqual("test1", host.default_value)
Пример #5
0
    def test_ObjectStorage___add_apis__valid_parms_returns_task_id(self):
        self._add_dummy_node('test1')

        result = self.svc.ObjectStorage___add_apis(["test1"], {})
        self.assertEqual(result, "task_id")

        dummy_node = self._get_dummy_node()
        role_list = dummy_node.get_roles()
        self.assertEqual([
            Role.get_by_name("memcached"),
            Role.get_by_name("openstack-swift-proxy")
        ], role_list)

        proxy_address = ConfigClassParameter.\
                                    get_by_name("SWIFT_PROXY_ADDRESS")
        self.assertEqual("test1", proxy_address.default_value)
Пример #6
0
    def test_Identity___add_auth__valid_parms_returns_task_id(self):
        self._add_dummy_node('test1')

        result = self.svc.Identity___add_auth("test1", {})
        self.assertEqual(result, "task_id")

        dummy_node = self._get_dummy_node()
        role_list = dummy_node.get_roles()
        self.assertEqual([
            Role.get_by_name("openstack-keystone-auth"),
            Role.get_by_name("openstack-keystone-admin")
        ], role_list)

        hostname = ConfigClassParameter.\
                                    get_by_name("KEYSTONE_HOST")
        self.assertEqual("test1", hostname.default_value)
Пример #7
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)
Пример #8
0
    def test_ObjectStorage___add_workers__valid_parms_returns_task_id(self):
        self._add_dummy_node('test1')

        result = self.svc.ObjectStorage___add_workers(
            ["test1"], {"SWIFT_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-swift-account"),
            Role.get_by_name("openstack-swift-container"),
            Role.get_by_name("openstack-swift-object"),
            Role.get_by_name("openstack-swift-rsync"),
            Role.get_by_name("os-vpx-ring-builder")
        ], role_list)

        overrides = dummy_node.get_overrides_dict()
        self.assertEqual("111.111.111.0", overrides["SWIFT_NODES_IPS"])
Пример #9
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
Пример #10
0
    def test_Scheduling___add_workers__valid_parms_returns_task_id(self):
        self._add_dummy_node('test1')

        result = self.svc.Scheduling___add_workers(["test1"], {})
        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-scheduler")],
                         role_list)
Пример #11
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)
Пример #12
0
 def _add_dummy_node_into_role(
     self,
     fqdn='test_fqdn',
     roles=["openstack-dashboard"],
     is_enabled=True,
 ):
     node = self._add_dummy_node(fqdn, is_enabled)
     for role in roles:
         r = Role.get_by_name(role)
         NodeRoleAssignment.objects.create(node=node,
                                           role=r,
                                           enabled=r.service)
     return node
Пример #13
0
    def test_Node___copy(self):
        self._add_dummy_node('node1')
        node2 = self._add_dummy_node('node2')
        self.svc.Compute___add_workers(["node1"], {})

        self.svc.Node___copy("node1", "node2")

        # ensure node2 has the compute role
        role_list = node2.get_roles()
        self.assertEqual([Role.get_by_name("openstack-nova-compute")],
                         role_list)
        # ensure node1 has been deleted
        self.assertListEqual(["node2"], self.svc.Node___get_all())
Пример #14
0
    def test_Network___add_workers__valid_flat_parms_returns_task_id(self):
        self._add_dummy_node('test1')

        result = self.svc.Network___add_workers(["test1"], {"MODE": "flat"})
        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-network")],
                         role_list)

        network_manager = ConfigClassParameter.\
                                get_by_name("NETWORK_MANAGER")
        self.assertEqual("nova.network.manager.FlatManager",
                         network_manager.default_value)
Пример #15
0
    def test_Imaging___add_registry_valid_parms_returns_task_id(self):
        self._add_dummy_node('test1')

        result = self.svc.Imaging___add_registry(
            "test1", {
                "GLANCE_STORE": "file",
                "GLANCE_FILE_STORE_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-glance-api"),
            Role.get_by_name("openstack-glance-registry")
        ], role_list)

        overrides = dummy_node.get_overrides_dict()
        self.assertEqual("file", overrides["GLANCE_STORE"])
        self.assertEqual("5", overrides["GLANCE_FILE_STORE_SIZE_GB"])

        host = ConfigClassParameter.\
                                get_by_name("GLANCE_HOSTNAME")
        self.assertEqual("test1", host.default_value)
Пример #16
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)
Пример #17
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)
Пример #18
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
Пример #19
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)
Пример #20
0
 def test_configs_get_by_role(self):
     role = Role.get_by_name('openstack-glance-api')
     configs = role.get_config_labels()
     logger.debug(configs)
     self.assertGreater(len(configs), 1)
Пример #21
0
 def test_get_role_dict(self):
     roles = Role.get_roles_dict()
     self.assertEquals(roles['openstack-nova-api'],
                       'OpenStack Compute API')
Пример #22
0
 def test_get_service_roles(self):
     roles = Role.get_service_roles()
     self.assertGreater(len(roles), 0)
Пример #23
0
 def test_get_node_details_default_roles(self):
     node = self._add_dummy_node_into_role('test', DEFAULT_ROLES)
     roles = [Role.get_by_name(r) for r in DEFAULT_ROLES]
     self._test_get_node_details_with_roles(node, roles)