def test_to_paramiko_private_key(self): pk_str = c.generate_private_key() pk = c.to_paramiko_private_key(pk_str) self.assertIsNotNone(pk) self.assertEqual(2048, pk.size) self.assertEqual('ssh-rsa', pk.get_name())
class Cluster(mb.SavannaBase): """Contains all info about cluster.""" __tablename__ = 'clusters' __table_args__ = (sa.UniqueConstraint('name', 'tenant_id'), ) id = _id_column() name = sa.Column(sa.String(80), nullable=False) description = sa.Column(sa.Text) tenant_id = sa.Column(sa.String(36)) plugin_name = sa.Column(sa.String(80), nullable=False) hadoop_version = sa.Column(sa.String(80), nullable=False) cluster_configs = sa.Column(st.JsonDictType()) default_image_id = sa.Column(sa.String(36)) anti_affinity = sa.Column(st.JsonListType()) private_key = sa.Column(sa.Text, default=crypto.generate_private_key()) user_keypair_id = sa.Column(sa.String(80)) status = sa.Column(sa.String(80)) status_description = sa.Column(sa.String(200)) info = sa.Column(st.JsonDictType()) node_groups = relationship('NodeGroup', cascade="all,delete", backref='cluster', lazy='joined') cluster_template_id = sa.Column(sa.String(36), sa.ForeignKey('cluster_templates.id')) cluster_template = relationship('ClusterTemplate', backref="clusters", lazy='joined') def to_dict(self): d = super(Cluster, self).to_dict() d['node_groups'] = [ng.to_dict() for ng in self.node_groups] return d
def _create_cluster_mock(node_groups, aa): cluster = m.Cluster("test_cluster", "tenant_id", "mock_plugin", "mock_version", "initial", user_keypair_id='user_keypair', anti_affinity=aa) cluster._user_kp = mock.Mock() cluster._user_kp.public_key = "123" cluster.private_key = c.generate_private_key() cluster.node_groups = node_groups return cluster
def _create_cluster_mock(node_groups, aa): user_kp = mock.Mock() user_kp.public_key = "123" private_key = c.generate_private_key() dct = {'name': 'test_cluster', 'plugin_name': 'mock_plugin', 'hadoop_version': 'mock_version', 'default_image_id': 'initial', 'user_keypair_id': 'user_keypair', 'anti_affinity': aa, '_user_kp': user_kp, 'private_key': private_key, 'node_groups': node_groups} cluster = conductor.cluster_create(context.ctx(), dct) return cluster
def _create_cluster_mock(node_groups, aa): user_kp = mock.Mock() user_kp.public_key = "123" private_key = c.generate_private_key() dct = { 'name': 'test_cluster', 'plugin_name': 'mock_plugin', 'hadoop_version': 'mock_version', 'default_image_id': 'initial', 'user_keypair_id': 'user_keypair', 'anti_affinity': aa, '_user_kp': user_kp, 'private_key': private_key, 'node_groups': node_groups } cluster = conductor.cluster_create(context.ctx(), dct) return cluster
def test_private_key_to_public_key(self): key = c.private_key_to_public_key(c.generate_private_key()) self.assertIsNotNone(key) self.assertIn('ssh-rsa', key)
def test_generate_private_key(self): pk = c.generate_private_key() self.assertIsNotNone(pk) self.assertIn('-----BEGIN RSA PRIVATE KEY-----', pk) self.assertIn('-----END RSA PRIVATE KEY-----', pk)