def test_modify_add_instance(self):
        _, _, _, deployment = self.put_deployment(
            deployment_id=str(uuid.uuid4()),
            blueprint_file_name='modify1.yaml')

        node_instances1 = self.client.node_instances.list()
        self.assertEqual(2, len(node_instances1))
        self._assert_number_of_instances(deployment.id, 'node1', 1, 1)

        modified_nodes = {'node1': {'instances': 2}}
        modification = self.client.deployment_modifications.start(
            deployment.id, nodes=modified_nodes)

        self._assert_number_of_instances(deployment.id, 'node1', 1, 1)

        node_instances2 = self.client.node_instances.list()
        self.assertEqual(3, len(node_instances2))

        initial_instance_ids = [i2.id for i2 in node_instances1]
        new_instances = [i for i in node_instances2
                         if i.id not in initial_instance_ids]
        old_instances = [i for i in node_instances2
                         if i.id in initial_instance_ids]
        self.assertEqual(1, len(new_instances))
        self.assertEqual(2, len(old_instances))

        new_instance = new_instances[0]
        self.assertEqual('node1', new_instance.node_id)
        expected_old_instances = copy.deepcopy(node_instances1)
        for instance in expected_old_instances:
            if instance.node_id == 'node2':
                current_relationship = instance.relationships[0]
                new_relationship = copy.deepcopy(current_relationship)
                new_relationship['target_id'] = new_instance.id
                instance.relationships.append(new_relationship)
        self.assertEqual(sorted(old_instances, key=lambda _i: _i.id),
                         sorted(expected_old_instances, key=lambda _i: _i.id))

        added_and_related = modification.node_instances.added_and_related
        self.assertEqual(2, len(added_and_related))

        self.client.deployment_modifications.finish(modification.id)

        self._assert_number_of_instances(deployment.id, 'node1', 2, 1)

        node_instances3 = self.client.node_instances.list()
        self.assertEqual(3, len(node_instances3))

        node1_instance_ids = [i.id for i in node_instances3
                              if i.node_id == 'node1']
        node2_instance = [i for i in node_instances3
                          if i.node_id == 'node2'][0]
        node2_target_ids = [rel['target_id'] for rel
                            in node2_instance.relationships]
        self.assertEqual(set(node1_instance_ids), set(node2_target_ids))
dataset/ETHPy150Open cloudify-cosmo/cloudify-manager/rest-service/manager_rest/test/test_modify.py/ModifyTests.test_modify_add_instance/original