def test_cluster_from_to_list(): input_dict = [{ 'uid': 0, 'ip': '0.0.0.0', 'port': 11 }, { 'uid': 1, 'ip': '1.1.1.1', 'port': 22 }, { 'uid': 2, 'ip': '2.2.2.2', 'port': 33 }] cluster = Cluster.from_list(input_dict, settings) exported = cluster.to_list() assert isinstance(exported, list) assert exported == input_dict assert len(cluster.instances) == 3 for i, instance in enumerate(cluster.instances): assert isinstance(instance, BareInstance) assert cluster.instances[i].uid == i assert cluster.instances[i].ip == '{0}.{0}.{0}.{0}'.format(i) assert cluster.instances[i].port == 11 * (i + 1)
def read_instances(self): """ Read `.dsb/instances.yaml` Populates `self.cluster` """ logger.debug('Reading instances from: %s' % self.instances_path) if os.path.exists(self.instances_path): with open(self.instances_path, 'r') as f: list_ = yaml.load(f.read()) self.cluster = Cluster.from_list(list_, settings=self.settings)
def test_cluster_from_to_list(): data = [{"id": 0, "ip": "0.0.0.0"}, {"id": 1, "ip": "1.1.1.1"}, {"id": 2, "ip": "2.2.2.2"}] cluster = Cluster.from_list(data, settings) exported = cluster.to_list() exported_ans = [{"id": 0, "ip": "0.0.0.0"}, {"id": 1, "ip": "1.1.1.1"}, {"id": 2, "ip": "2.2.2.2"}] assert isinstance(exported, list) assert exported == exported_ans assert len(cluster.instances) == 3
def read_instances(self): """ Read `.dsb/instances.yaml` Populates `self.cluster` """ logger.debug('Reading instances from: %s', self.instances_path) if os.path.exists(self.instances_path): with open(self.instances_path, 'r') as f: list_ = yaml.load(f.read()) self.cluster = Cluster.from_list(list_, settings=self.settings)
def test_cluster_from_to_list(): input_dict = [{'uid': 0, 'ip': '0.0.0.0', 'port': 11}, {'uid': 1, 'ip': '1.1.1.1', 'port': 22}, {'uid': 2, 'ip': '2.2.2.2', 'port': 33}] cluster = Cluster.from_list(input_dict, settings) exported = cluster.to_list() assert isinstance(exported, list) assert exported == input_dict assert len(cluster.instances) == 3 for i, instance in enumerate(cluster.instances): assert isinstance(instance, BareInstance) assert cluster.instances[i].uid == i assert cluster.instances[i].ip == '{0}.{0}.{0}.{0}'.format(i) assert cluster.instances[i].port == 11 * (i + 1)
import pytest from datasciencebox.core.project import Project from datasciencebox.core.settings import Settings from datasciencebox.core.cloud.cluster import Cluster settings = Settings() settings['USERNAME'] = '******' settings['KEYPAIR'] = '~/.ssh/id_rsa' _ = [{'id': 0, 'ip': '0.0.0.0'}, {'id': 1, 'ip': '1.1.1.1'}, {'id': 2, 'ip': '2.2.2.2'}] cluster = Cluster.from_list(_, settings) project = Project() project.settings = settings project.cluster = cluster