Ejemplo n.º 1
0
 def setUp(self):
     self.client = Client()
     new_user = get_user_model().objects.create_superuser(**SUPER_USER)
     new_user.save()
     cluster = Cluster(**CLUSTER)
     cluster.save()
     self.cluster = cluster
     credential = Credential(
         user=new_user,
         cluster=cluster,
         **CREDENTIAL)
     credential.save()
     self.credential = credential
Ejemplo n.º 2
0
class UtilsServerTestCase(TestCase):

    def setUp(self):
        self.user = get_user_model().objects.create_user(**USER)
        test_path = os.path.join(settings.MEDIA_ROOT, "tests")
        with open(os.path.join(test_path, "id_rsa.pub"), 'r') as f:
            self.user.public_key = f.read()
        with open(os.path.join(test_path, "id_rsa"), 'r') as f:
            self.user.private_key = f.read()
        self.user.save()

        super_user = get_user_model().objects.create_superuser(**SUPER_USER)
        super_user.save()


        self.cluster = Cluster(**CLUSTER)
        self.cluster.save()
        self.credential = Credential(
            user=self.user, cluster=self.cluster, **CREDENTIAL)
        self.credential.save()
        self.credential2 = Credential(
            user=super_user, cluster=self.cluster, **CREDENTIAL)
        self.credential2.save()

    def test_run_standard_jobs_staff_error(self):
        results = utils.run_standard_jobs(self.credential, [''], {}, {})
        self.assertEqual(results["error"], SUBMIT_ERROR)

    def test_run_standard_jobs_invalid_credential(self):
        results = utils.run_standard_jobs(None, [''], {}, {})
        self.assertEqual(results["error"], CRED_ERROR)

    def test_run_standard_jobs(self):
        job = 'sleep 10'
        names = "TON,CON"
        results = utils.run_standard_jobs(
            self.credential2, names, {}, {'jobstring': job})
        self.assertEqual(results["error"], None)
        self.assertEqual(results["failed"], [])

    def test_run_standard_jobs_name_error(self):
        job = 'sleep 10'
        names = "E-N,C-N"
        results = utils.run_standard_jobs(
            self.credential2, names, {}, {'jobstring': job})
        for name, error in results['failed']:
            self.assertEqual(error, "Bad Substituent Name(s): ['N']")
Ejemplo n.º 3
0
    def setUp(self):
        self.user = get_user_model().objects.create_user(**USER)
        test_path = os.path.join(settings.MEDIA_ROOT, "tests")
        with open(os.path.join(test_path, "id_rsa.pub"), 'r') as f:
            self.user.public_key = f.read()
        with open(os.path.join(test_path, "id_rsa"), 'r') as f:
            self.user.private_key = f.read()
        self.user.save()

        super_user = get_user_model().objects.create_superuser(**SUPER_USER)
        super_user.save()


        self.cluster = Cluster(**CLUSTER)
        self.cluster.save()
        self.credential = Credential(
            user=self.user, cluster=self.cluster, **CREDENTIAL)
        self.credential.save()
        self.credential2 = Credential(
            user=super_user, cluster=self.cluster, **CREDENTIAL)
        self.credential2.save()
Ejemplo n.º 4
0
    def setUp(self):
        self.mock_ssh, self.mock_sftp = build_mock_connections(self)
        self.client = Client()
        for user in self.users:
            new_user = get_user_model().objects.create_user(
                user["username"], user["email"], user["new_password1"])
            new_user.save()

        user = get_user_model().objects.all()[0]
        profile = user
        test_path = os.path.join(settings.MEDIA_ROOT, "tests")
        with open(os.path.join(test_path, "id_rsa.pub"), 'r') as f:
            profile.public_key = f.read()
        with open(os.path.join(test_path, "id_rsa"), 'r') as f:
            profile.private_key = f.read()
        profile.save()

        cluster = Cluster(name=self.cluster["name"],
                          hostname=self.cluster["hostname"],
                          port=self.cluster["port"])
        cluster.save()
        self.cluster = cluster
        credential = Credential(user=user,
                                cluster=cluster,
                                username=self.credential["username"],
                                password='',
                                use_password=False)
        credential.save()
        self.credential = credential
        credential2 = Credential(user=user,
                                 cluster=cluster,
                                 username=self.credential.username,
                                 password="******",
                                 use_password=True)
        credential2.save()
        self.credential2 = credential2
Ejemplo n.º 5
0
    def setUp(self):
        self.client = Client()
        for user in self.users:
            new_user = get_user_model().objects.create_user(user["username"],
                                                user["email"],
                                                user["new_password1"])
            new_user.save()

        user = get_user_model().objects.all()[0]
        profile = user
        test_path = os.path.join(settings.MEDIA_ROOT, "tests")
        with open(os.path.join(test_path, "id_rsa.pub"), 'r') as f:
            profile.public_key = f.read()
        with open(os.path.join(test_path, "id_rsa"), 'r') as f:
            profile.private_key = f.read()
        profile.save()

        cluster = Cluster(
            name=self.cluster["name"],
            hostname=self.cluster["hostname"],
            port=self.cluster["port"])
        cluster.save()
        self.cluster = cluster
        credential = Credential(
            user=user,
            cluster=cluster,
            username=self.credential["username"],
            password='',
            use_password=False)
        credential.save()
        self.credential = credential
        credential2 = Credential(
            user=user,
            cluster=cluster,
            username=self.credential.username,
            password="******",
            use_password=True)
        credential2.save()
        self.credential2 = credential2

        s = "cp ~/.ssh/authorized_keys ~/.ssh/authorized_keys.chemtools.bak"
        with self.credential.get_ssh_connection() as ssh:
            ssh.exec_command(s)
Ejemplo n.º 6
0
    def setUp(self):
        self.mock_ssh, self.mock_sftp = build_mock_connections(self)
        self.client = Client()
        for user in self.users:
            new_user = get_user_model().objects.create_user(user["username"],
                                                user["email"],
                                                user["new_password1"])
            new_user.save()

        user = get_user_model().objects.all()[0]
        profile = user
        test_path = os.path.join(settings.MEDIA_ROOT, "tests")
        with open(os.path.join(test_path, "id_rsa.pub"), 'r') as f:
            profile.public_key = f.read()
        with open(os.path.join(test_path, "id_rsa"), 'r') as f:
            profile.private_key = f.read()
        profile.save()

        cluster = Cluster(
            name=self.cluster["name"],
            hostname=self.cluster["hostname"],
            port=self.cluster["port"])
        cluster.save()
        self.cluster = cluster
        credential = Credential(
            user=user,
            cluster=cluster,
            username=self.credential["username"],
            password='',
            use_password=False)
        credential.save()
        self.credential = credential
        credential2 = Credential(
            user=user,
            cluster=cluster,
            username=self.credential.username,
            password="******",
            use_password=True)
        credential2.save()
        self.credential2 = credential2