def test_multiple_constraints(self):
     fake_client = Mock(wraps=fake_juju_client())
     with patch('assess_constraints.prepare_constraint_test',
                autospec=True,
                side_effect=[
                    {
                        'root-disk': '8G',
                        'cpu-power': '40'
                    },
                    {
                        'root-disk': '15G',
                        'cpu-power': '20'
                    },
                    {
                        'root-disk': '15G',
                        'cpu-power': '40'
                    },
                ]) as prepare_mock:
         assess_multiple_constraints(fake_client,
                                     'test',
                                     root_disk='15G',
                                     cpu_power='40')
     self.assertEqual(3, prepare_mock.call_count)
     prepare_mock.assert_has_calls([
         call(fake_client, Constraints(cpu_power='40'), 'test-part0'),
         call(fake_client, Constraints(root_disk='15G'), 'test-part1'),
         call(fake_client, Constraints(root_disk='15G', cpu_power='40'),
              'test-whole'),
     ])
 def test_constraints_deploy_instance_type(self):
     constraints_list = [
         Constraints(instance_type='bar'),
         Constraints(instance_type='baz')
     ]
     expected_calls = ['instance-type=bar', 'instance-type=baz']
     with self.prepare_deploy_mock() as (fake_client, deploy_mock):
         fake_provider = fake_client.env.provider
         with self.patch_instance_spec(fake_provider):
             for constraints in constraints_list:
                 assess_constraints_deploy(fake_client, constraints,
                                           'tests')
     constraints_calls = self.gather_constraint_args(deploy_mock)
     self.assertEqual(constraints_calls, expected_calls)
 def test_deploy_charm_constraint(self):
     fake_client = Mock(wraps=fake_juju_client())
     charm_name = 'test-constraint'
     charm_series = 'xenial'
     constraints = Constraints(mem='10GB')
     with temp_dir() as charm_dir:
         with patch('assess_constraints.deploy_constraint',
                    autospec=True) as deploy_mock:
             deploy_charm_constraint(fake_client, constraints, charm_name,
                                     charm_series, charm_dir)
     charm = os.path.join(charm_dir, charm_series, charm_name)
     deploy_mock.assert_called_once_with(fake_client, constraints, charm,
                                         charm_series, charm_dir)
 def test_meets_instance_type(self):
     constraints = Constraints(instance_type='t2.micro')
     data1 = {'mem': '1G', 'cpu-power': '10', 'cores': '1'}
     self.assertTrue(constraints.meets_instance_type(data1))
     data2 = {'mem': '8G', 'cpu-power': '20', 'cores': '1'}
     self.assertFalse(constraints.meets_instance_type(data2))
     data3 = dict(data1, arch='amd64')
     self.assertTrue(constraints.meets_instance_type(data3))
     data4 = {'root-disk': '1G', 'cpu-power': '10', 'cores': '1'}
     with self.assertRaises(JujuAssertionError):
         constraints.meets_instance_type(data4)
    def inner_test_constraints_deploy(self, tests_specs):
        """Run a test or series of tests on assess_constraints_deploy.

        :param tests_spec: List of 3 tuples (Constraints args dict, expected
        constraint argument on deploy, return value for data)."""
        constraints_list = [spec[0] for spec in tests_specs]
        expected_call_list = [spec[1] for spec in tests_specs]
        patch_return_list = [spec[2] for spec in tests_specs]
        with self.patch_hardware(patch_return_list):
            with self.prepare_deploy_mock() as (fake_client, deploy_mock):
                for constraints_args in constraints_list:
                    constraints = Constraints(**constraints_args)
                    assess_constraints_deploy(fake_client, constraints,
                                              'tests')
        constraints_calls = self.gather_constraint_args(deploy_mock)
        self.assertEqual(constraints_calls, expected_call_list)
Exemplo n.º 6
0
 def test_meets_instance_type(self):
     constraints = Constraints(instance_type='t2.micro')
     data1 = {'mem': '1G', 'cpu-power': '10', 'cores': '1'}
     self.assertTrue(constraints.meets_instance_type(data1))
     data2 = {'mem': '8G', 'cpu-power': '20', 'cores': '1'}
     self.assertFalse(constraints.meets_instance_type(data2))
     data3 = dict(data1, arch='amd64')
     self.assertTrue(constraints.meets_instance_type(data3))
     data4 = {'root-disk': '1G', 'cpu-power': '10', 'cores': '1'}
     with self.assertRaises(JujuAssertionError):
         constraints.meets_instance_type(data4)
 def test_deploy_constraint(self):
     fake_client = Mock(wraps=fake_juju_client())
     fake_client.attach_mock(Mock(), 'deploy')
     fake_client.attach_mock(Mock(), 'wait_for_workloads')
     charm_name = 'test-constraint'
     charm_series = 'xenial'
     constraints = Constraints(mem='10GB')
     with temp_dir() as charm_dir:
         charm = os.path.join(charm_dir, charm_series, charm_name)
         deploy_constraint(fake_client, constraints, charm, charm_series,
                           charm_dir)
     fake_client.deploy.assert_called_once_with(
         charm,
         series=charm_series,
         repository=charm_dir,
         constraints=str(constraints))
     fake_client.wait_for_workloads.assert_called_once_with()
Exemplo n.º 8
0
 def test_meets_cpu_power(self):
     constraints = Constraints(cpu_power='20')
     self.assertTrue(constraints.meets_cpu_power('30'))
     self.assertFalse(constraints.meets_cpu_power('10'))
 def test_meets_cpu_power(self):
     constraints = Constraints(cpu_power='20')
     self.assertTrue(constraints.meets_cpu_power('30'))
     self.assertFalse(constraints.meets_cpu_power('10'))
Exemplo n.º 10
0
 def test_meets_instance_type_fix(self):
     constraints = Constraints(instance_type='t2.micro')
     data = {'mem': '1G', 'cpu-power': '10', 'cpu-cores': '1'}
     self.assertTrue(constraints.meets_instance_type(data))
Exemplo n.º 11
0
 def test_meets_arch(self):
     constraints = Constraints(arch='amd64')
     self.assertTrue(constraints.meets_arch('amd64'))
     self.assertFalse(constraints.meets_arch('arm64'))
 def test_meets_instance_type_none(self):
     constraints = Constraints()
     data = {'mem': '1G', 'cores': '1'}
     self.assertTrue(constraints.meets_instance_type(data))
 def test_meets_all(self):
     constraints = Constraints(cores='2', arch='amd64')
     data1 = {'cores': '2', 'arch': 'amd64'}
     self.assertTrue(constraints.meets_all(data1))
     data2 = {'cores': '1', 'arch': 'amd64'}
     self.assertFalse(constraints.meets_all(data2))
Exemplo n.º 14
0
 def test_meets_cores(self):
     constraints = Constraints(cores='2')
     self.assertTrue(constraints.meets_cores('3'))
     self.assertFalse(constraints.meets_cores('1'))
 def test_meets_instance_type_fix(self):
     constraints = Constraints(instance_type='t2.micro')
     data = {'mem': '1G', 'cpu-power': '10', 'cpu-cores': '1'}
     self.assertTrue(constraints.meets_instance_type(data))
 def test_str_operator(self):
     constraints = Constraints(mem='2G', root_disk='4G', virt_type='lxd')
     self.assertEqual('mem=2G virt-type=lxd root-disk=4G', str(constraints))
Exemplo n.º 17
0
 def test_meets_instance_type_none(self):
     constraints = Constraints()
     data = {'mem': '1G', 'cores': '1'}
     self.assertTrue(constraints.meets_instance_type(data))
 def test_meets_cores(self):
     constraints = Constraints(cores='2')
     self.assertTrue(constraints.meets_cores('3'))
     self.assertFalse(constraints.meets_cores('1'))
 def test_meets_root_disk(self):
     constraints = Constraints(root_disk='8G')
     self.assertTrue(constraints.meets_root_disk('8G'))
     self.assertFalse(constraints.meets_root_disk('4G'))
Exemplo n.º 20
0
 def test_meets_all(self):
     constraints = Constraints(cores='2', arch='amd64')
     data1 = {'cores': '2', 'arch': 'amd64'}
     self.assertTrue(constraints.meets_all(data1))
     data2 = {'cores': '1', 'arch': 'amd64'}
     self.assertFalse(constraints.meets_all(data2))
 def test_repr_operator(self):
     self.assertEqual("Constraints()", repr(Constraints()))
     constraints = Constraints(root_disk='4G', mem='2G')
     self.assertEqual("Constraints(mem='2G', root_disk='4G')",
                      repr(constraints))
 def test_meets_arch(self):
     constraints = Constraints(arch='amd64')
     self.assertTrue(constraints.meets_arch('amd64'))
     self.assertFalse(constraints.meets_arch('arm64'))
 def test_str_operator_none(self):
     self.assertEqual('', str(Constraints()))
     self.assertEqual('', str(Constraints(arch=None)))
Exemplo n.º 24
0
 def test_meets_root_disk(self):
     constraints = Constraints(root_disk='8G')
     self.assertTrue(constraints.meets_root_disk('8G'))
     self.assertFalse(constraints.meets_root_disk('4G'))